如何创建与Android的圆角一个ListView? [英] How do I create a ListView with rounded corners in Android?

查看:202
本文介绍了如何创建与Android的圆角一个ListView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Android中如何创建一个带有圆角的ListView的?

How do I create a ListView with rounded corners in Android?

推荐答案

下面是这样做的一种方式(尽管由于Android的文件!):

Here is one way of doing it (Thanks to Android Documentation though!):

添加以下到一个文件中(比如customshape.xml),然后将其放置在(RES /绘制/ customshape.xml)

Add the following into a file (say customshape.xml) and then place it in (res/drawable/customshape.xml)

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
     android:shape="rectangle"> 
     <gradient 
         android:startColor="#SomeGradientBeginColor"
         android:endColor="#SomeGradientEndColor" 
         android:angle="270"/> 

    <corners 
         android:bottomRightRadius="7dp" 
         android:bottomLeftRadius="7dp" 
         android:topLeftRadius="7dp" 
         android:topRightRadius="7dp"/> 
</shape> 

一旦你与​​创建这个文件做了,只是将背景设置在以下方式之一:

Once you are done with creating this file, just set the background in one of the following ways:

通过code: listView.setBackgroundResource(R.drawable.customshape);

通过XML ,只是下面的属性添加到容器(例如:的LinearLayout或任何字段):

Through XML, just add the following attribute to the container (ex: LinearLayout or to any fields):

android:background="@drawable/customshape"

希望有人发现它有用...

Hope someone finds it useful...

这篇关于如何创建与Android的圆角一个ListView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆