首页 > 其他分享 >圆角背景的ListView

圆角背景的ListView

时间:2023-05-01 14:04:30浏览次数:46  
标签:圆角 背景 list convertView context position ListView public


先定义一张圆角的图片shape_bg_listview.xml

<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" 
       android:shape="rectangle"
       >
       <gradient  
       android:startColor="@android:color/white"  
       android:endColor="#FFCCCCCC"  
       android:angle="180" 
       />
       <stroke android:width="0px" 
       android:color="@android:color/white" 
       /> 
       <solid android:color="@android:color/white" 
       /> 
       <corners 
       android:bottomRightRadius="20px" 
       android:bottomLeftRadius="20px" 
       android:topLeftRadius="20px" 
       android:topRightRadius="20px" 
       />
</shape>



然后在ListView中引用它,注意android:listSelector为了去掉选中效果:


<ListView android:id="@+id/list" 		android:layout_width="fill_parent" 
		android:layout_height="wrap_content"
		android:layout_margin="20.0dip"
		android:cacheColorHint="@null" 
                android:listSelector="@drawable/shape_bg_listview"
		android:background="@drawable/shape_bg_listview"
		/>



代码:


public class App extends Activity {
	private ListView mListView = null;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ArrayList<String> list =new ArrayList<String>();
        list.add("1");
        list.add("2");
        list.add("3");
        mListView =  (ListView)findViewById(R.id.list);
        mListView.setAdapter(new AppAdapter(this,list));
    }
    
    class AppAdapter extends BaseAdapter{

    	Context context;
    	ArrayList<String> list;
    	AppAdapter(Context context,ArrayList<String> list){
    		this.context=context;
    		this.list=list;
    	}
		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return list.size();
		}

		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return list.get(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
			TextView tv;
			if(convertView==null){
				convertView=LayoutInflater.from(context).inflate(R.layout.simple_item_2, null);
			}
			tv=(TextView)convertView.findViewById(R.id.name);
			tv.setText(list.get(position));
			return convertView;
		}
    	
    }
}




simple_item_2.xml定义如下:


<?xml version="1.0" encoding="utf-8"?><RelativeLayout
	xmlns:android="http://schemas.android.com/apk/res/android"
	android:layout_width="fill_parent"
	android:layout_height="wrap_content"
	>
	<TextView
		android:id="@+id/name"
		android:textSize="17.0sp"
		android:textColor="@android:color/black"
		android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:layout_marginLeft="20.0dip"
		android:layout_alignParentLeft="true"
		android:layout_centerVertical="true"
		>
	</TextView>
	<ImageView
		android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:layout_marginRight="20.0dip"
		android:src="@drawable/arrow"
		android:layout_alignParentRight="true"
		android:layout_centerVertical="true"
		>
	</ImageView>
</RelativeLayout>




App列表之圆角ListView(续)

  • 圆角背景的ListView_xml

  • 大小: 5.4 KB
  • Test_radio.rar (58.2 KB)
  • 下载次数: 215
  • 查看图片附件

标签:圆角,背景,list,convertView,context,position,ListView,public
From: https://blog.51cto.com/u_5454003/6238867

相关文章

  • Android提高第十五篇之ListView自适应实现表格
    上次介绍了使用GridView实现表格,这次就说说如何用ListView实现自适应的表格。GridView比ListView更容易实现自适应的表格,但是GridView每个格单元的大小固定,而ListView实现的表格可以自定义每个格单元的大小,但因此实现自适应表格也会复杂些(格单元大小不一)。......
  • ListView性能
    ListView是一种可以显示一系列项目并能进行滚动显示的View。在每行里,既可以是简单的文本,也可以是复杂的结构。一般情况下,你都需要保证ListView运行得很好(即:渲染更快,滚动流畅)。在接下来的内容里,我将就ListView的使用,向大家提供几种解决不同性能问题的解决方案。如果你想使用ListView......
  • Android ListView 去除…
    去除ListView滑到顶部和底部时边缘的黑色阴影:android:fadingEdge="none"----------------------------------------------------去除拖动时默认的黑色背景:android:cacheColorHint="#00000000" 或listView.setCacheColorHint(Color.TRANSPARENT);---------------------......
  • 如何在Godot中使用ParallaxBackground实现稳定的2d游戏背景[一问随笔]
    问题:我尝试给2d游戏添加静态的背景,当角色运动速度很快时相机的渲染就跟不上角色了,背景会发生这样巨大的位移。我将Camera2d节点和背景节点绑在一起,但根本无法解决这个问题。我还尝试制作天空盒子作为解决方案,有没有什么更好的方案?解决:Godot提供了两种节点ParallaxBa......
  • m基于背景差法与GMM混合高斯模型结合的红外目标检测与跟踪算法matlab仿真
    1.算法仿真效果matlab2013b仿真结果如下: 普通视频:  红外视频:   2.算法涉及理论知识概要       在Stauffer等人提出的自适应混合高斯背景模型基础上,为每个像素构建混合高斯背景模型,通过融入帧间差分把每帧中的图像区分为背景区域、背景显露区域和运动物......
  • m基于背景差法与GMM混合高斯模型结合的红外目标检测与跟踪算法matlab仿真
    1.算法仿真效果matlab2013b仿真结果如下:普通视频:红外视频:2.算法涉及理论知识概要在Stauffer等人提出的自适应混合高斯背景模型基础上,为每个像素构建混合高斯背景模型,通过融入帧间差分把每帧中的图像区分为背景区域、背景显露区域和运动物体区域。相对于背景区域,背景显露......
  • 去除echart鼠标经过图表时默认背景黄色问题
    废话不说,上代码:策一://注册mouseover事件,去除hover样式myChart.on("mouseover",function(){myChart.dispatchAction({type:"downplay",})})策二(荐):geo:{emphasis:{disabled:true},}写在最后duang~这时候产品站出来了,说我要在......
  • Windows 10 应用创建模糊背景窗口的三种方法
    现代的操作系统中创建一张图片的高斯模糊效果非常容易,不过如果要在窗口中获得模糊支持就需要操作系统的原生支持了。iOS/Mac和Windows系统都对此有支持。本文将介绍三种创建模糊背景窗口的方法。有人可能喜欢称之为毛玻璃窗口、亚克力窗口。Thispostiswrittenin multip......
  • MFC-GetBkMode获取指定DC的背景混合模式
     HDChdc=::GetDC(m_hWnd);LOGFONTlf={0};lf.lfWeight=16;//平均宽度lf.lfHeight=40;//字体高度lf.lfCharSet=GB2312_CHARSET;//字符集lstrcpy(lf.lfFaceName,_T("宋体"));HFONThfont=::CreateFontIndirect(&lf)......
  • MFC-SetBkMode设置指定DC的背景混合模式
     HDChdc=::GetDC(m_hWnd);LOGFONTlf={0};lf.lfWeight=16;//平均宽度lf.lfHeight=40;//字体高度lf.lfCharSet=GB2312_CHARSET;//字符集lstrcpy(lf.lfFaceName,_T("宋体"));HFONThfont=::CreateFontIndirect(&lf)......