gpt4 book ai didi

android - 如何创建圆角形状的 ListView

转载 作者:行者123 更新时间:2023-11-29 14:19:53 25 4
gpt4 key购买 nike

如何在 Android 中制作简单的 ListView,我正在制作一个程序,我在其中以这种方式获取 ListView:

enter image description here

适配器.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp"
android:gravity="center_vertical"
android:padding="5dip" >

<!-- Title Of Song-->

<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="false"
android:text="Name"
android:textSize="15dip"
android:typeface="sans" />

</RelativeLayout>

Activity .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="fill_parent"
>

<ListView
android:id="@+id/listView1"
android:layout_below="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:divider="@android:color/black"
android:dividerHeight="1dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="20dp"/>

</RelativeLayout>

但我想制作这种简单的列表 [same List SHAPE] ,请看下面的屏幕:

enter image description here

最佳答案

根据您的要求

在您的可绘制文件夹中创建一个形状文件。将此 xml 放入其中并根据您的要求更改颜色。

 <?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/shape_my">
<stroke android:width="4dp" android:color="#636161" />
<padding android:left="5dp"
android:top="5dp"
android:right="5dp"
android:bottom="5dp" />
<corners android:radius="24dp" />
<solid android:color="#FFF" />
</shape>

ma​​in.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:orientation="vertical">

<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#b5b5b5"
android:dividerHeight="1dp"
android:listSelector="@drawable/list_selector" />

</LinearLayout>

在ListView中设置背景android:background="@drawable/shape"

list_row.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"
android:background="@drawable/list_selector"
android:orientation="horizontal"
android:padding="5dip" >

<TextView
android:id="@+id/category"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Category"
android:textColor="#040404"
android:textSize="15dip"
android:textStyle="bold"
android:typeface="sans" />

<TextView
android:id="@+id/expiry_date"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/category"
android:layout_marginTop="1dip"
android:text="Text here."
android:textColor="#343434"
android:textSize="10dip" />

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

</RelativeLayout>

关于android - 如何创建圆角形状的 ListView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19043455/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com