You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android Studio中如何设置ListView每个条目单独圆角效果

实现ListView单条目独立圆角的方案

你目前的实现问题出在两点:一是给ListView本身额外设置了圆角背景,导致整个列表外层出现统一圆角,二是分割线配置需要配合调整。

步骤1:修改ListView XML配置

删除ListView的android:background属性,同时将分割线设置为透明,避免分割线破坏独立条目视觉效果,修改后代码如下:

<ListView
        android:id="@+id/listDate"
        android:layout_width="fill_parent"
        android:layout_height="650dp"
        android:layout_marginTop="270dp"
        android:divider="@android:color/transparent"
        android:dividerHeight="10dp" />

步骤2:确认圆角drawable定义

确保你使用的@drawable/rounded_corner是四个角均带圆角的shape资源,参考代码(路径为res/drawable/rounded_corner.xml)如下,可自行调整圆角半径数值:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="#FFFFFF" />
    <corners android:radius="12dp" />
</shape>

步骤3:可选优化条目边距

如果需要条目和屏幕左右两侧保留间距,可以给list_rows.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:orientation="horizontal"
    android:background="@drawable/rounded_corner"
    android:layout_marginHorizontal="16dp"
    android:padding="15dip" >
    <TextView
        android:id="@+id/txtDat"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textStyle="bold"
        android:text="Date"
        android:textSize="25dp" />
</RelativeLayout>

完成以上修改后即可实现每个条目独立带圆角、条目之间存在透明间隔的目标效果。

内容的提问来源于stack exchange,提问作者MeltedIceCream

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.25 11:24:07