日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

android listview item 圆角,ListView圆角 实现方法(一)

發布時間:2025/3/20 编程问答 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android listview item 圆角,ListView圆角 实现方法(一) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

(本方法核心思想是 在適配器里面為 每一個item 添加

selector)

適配器里面代碼:

package com.blogtask.adapter;

import com.blogtask.activity.R;

import android.content.Context;

import android.view.LayoutInflater;

import android.view.View;

import android.view.ViewGroup;

import android.widget.BaseAdapter;

import android.widget.LinearLayout;

import android.widget.TextView;

public class demoadapter extends BaseAdapter {

private LayoutInflater inflater;

private String[] list;

private int resource;

public demoadapter(Context context,String[]

list,int resource){

this.inflater=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

this.list=list;

this.resource=resource;

}

@Override

public int getCount() {

// TODO Auto-generated method

stub

return list.length;

}

@Override

public Object getItem(int position) {

// TODO Auto-generated method

stub

return list[position];

}

@Override

public long getItemId(int position) {

// TODO Auto-generated method

stub

return position;

}

@Override

public View getView(int position, View

convertView, ViewGroup parent) {

// TODO Auto-generated method

stub

viewholder view=null;

if(convertView==null){

view=new

viewholder();

convertView=this.inflater.inflate(this.resource,

null);

//convertView.

convertView.setBackgroundResource(getbg(position));?view.tv=(TextView)convertView.findViewById(R.id.textView1);

convertView.setTag(view);

}else{

view=(viewholder)convertView.getTag();

}

view.tv.setText(list[position]);

return convertView;

}

private int getbg(int

position) {

// TODO Auto-generated method

stub

if(position==0&&list.length==1){?//僅一項

return

R.drawable.a_all;

}

if(position==0){?//第一項

return

R.drawable.a_top;

}

if(position==list.length-1){最后一項

return

R.drawable.a_bot;

}

return R.drawable.a_nor;

中間項

}?private final

class viewholder{

private TextView tv;

}

}

listview設置:

android:id="@+id/mylv"

android:listSelector="@android:color/transparent"

android:cacheColorHint="@android:color/transparent"?android:layout_width="match_parent"

android:layout_height="wrap_content" >

四個selector:1.中間項

android:state_pressed="true">

?

android:color="#d6ddf0">

android:state_focused="true">

?

android:color="#d6ddf0">

?

android:color="#ffffff">

2.第一項

android:state_pressed="true">

android:topRightRadius="8dip" />

android:color="#d6ddf0">

android:state_focused="true">

android:topRightRadius="8dip" />

android:color="#d6ddf0">

android:topRightRadius="8dip" />

android:color="#ffffff">

3.最后一項

android:state_pressed="true">

android:bottomRightRadius="8dip" />

android:color="#d6ddf0">

android:state_focused="true">

android:bottomRightRadius="8dip" />

android:color="#d6ddf0">

android:bottomRightRadius="8dip" />

android:color="#ffffff">

4.單獨一項

android:state_pressed="true">

android:topRightRadius="8dip" android:bottomLeftRadius="8dip"

android:bottomRightRadius="8dip" />

android:color="#d6ddf0">

android:state_focused="true">

android:topRightRadius="8dip"?android:bottomLeftRadius="8dip" android:bottomRightRadius="8dip"

/>

android:color="#d6ddf0">

android:topRightRadius="8dip"?android:bottomLeftRadius="8dip" android:bottomRightRadius="8dip"

/>

android:color="#ffffff">

總結

以上是生活随笔為你收集整理的android listview item 圆角,ListView圆角 实现方法(一)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。