android list圆角显示

本文介绍了一种使用Android实现特定列表视图的方法,包括定义不同情况下的选择器样式以实现圆角效果。通过LinearLayout和RelativeLayout布局,配合ExpandableListView组件及自定义的Drawable资源,实现了具有上下文敏感样式的列表项。

如实现上面的list效果:

一、contant_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/bg_color"
    android:orientation="vertical" >




    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="15dp"
        android:orientation="vertical"
        android:paddingLeft="15dp"
        android:paddingRight="15dp" >


        <RelativeLayout
            android:id="@+id/contant_all_item_02"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:background="@drawable/list_group_selector"
            android:clickable="true"
            android:padding="10dp" >


            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:src="@drawable/next_button" />


            <TextView
                style="@style/list_group_text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_weight="1"
                android:text="@string/allcontant_head" />
            
        </RelativeLayout>


        <ExpandableListView
            android:id="@+id/expandable01"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="15dp"
            android:background="@drawable/list_group_bg_item"
            android:drawSelectorOnTop="false" 
            android:groupIndicator="@null">
        </ExpandableListView>


        <RelativeLayout
            android:id="@+id/contant_all_item_03"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:background="@drawable/list_group_selector"
            android:clickable="true"
            android:padding="10dp" 
            android:layout_marginTop="15dp">


            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:src="@drawable/next_button" />


            <TextView
                style="@style/list_group_text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_weight="1"
                android:text="@string/seif_contant" />
        </RelativeLayout>
    </LinearLayout>


</LinearLayout>

二、定义选择器
1、如果只有一项,我们需要四个角都是圆角,app_list_corner_round.xml文件定义如下:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient android:startColor="#B5E7B8"
        android:endColor="#76D37B"
        android:angle="270"/>
    <corners android:topLeftRadius="4dip"
        android:topRightRadius="4dip"
        android:bottomLeftRadius="4dip"
        android:bottomRightRadius="4dip"/>
</shape> 
2、如果是顶部第一项,则上面两个角为圆角,app_list_corner_round_top.xml定义如下:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient android:startColor="#B5E7B8"
        android:endColor="#76D37B"
        android:angle="270"/>
    <corners android:topLeftRadius="4dip"
        android:topRightRadius="4dip"/>
</shape>
3、如果是底部最后一项,则下面两个角为圆角,app_list_corner_round_bottom.xml定义如下:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient android:startColor="#B5E7B8"
        android:endColor="#76D37B"
        android:angle="270"/>
    <corners android:bottomLeftRadius="4dip"
        android:bottomRightRadius="4dip" />
</shape> 
4、如果是中间项,则应该不需要圆角, app_list_corner_shape.xml定义如下:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient android:startColor="#B5E7B8"
        android:endColor="#76D37B"
        android:angle="270"/>
</shape>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Ada

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值