android listview圆角

标签 android android-listview

我尝试创建圆角listview.i创建了自定义xml文件并编写了这段代码

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/shape_my" >

<stroke
    android:width="2dp"
    android:color="#636161" />

<padding
    android:bottom="5dp"
    android:left="5dp"
    android:right="5dp"
    android:top="5dp" />

<corners android:radius="24dp" />

<solid android:color="#FFF" />

my listview looks same as a picture

but i want to recive like this style listview

这是我的自定义 ListView 适配器代码

<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"
>

<ImageView
    android:id="@+id/cat_image"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_centerVertical="true"
    android:layout_marginLeft="15dp" />

<TextView
    android:id="@+id/cat_title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:layout_marginLeft="15dp"
    android:layout_toRightOf="@+id/cat_image"
    android:text="TextView"
    android:textColor="#9577a9" />

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_centerVertical="true"
    android:layout_marginRight="19dp"
    android:background="@drawable/cat_next" />

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

我该如何解决我的问题?如果有人知道解决方案请帮助我 谢谢

最佳答案

检查this 。由于中间条目使用不同的样式,因此只有第一行和最后一行分别应用顶部和底部圆角。这可能会帮助您实现所需的目标。

所以你需要做的是:

如果项目位置是第一个或最后一个,则只需应用圆角样式 xml。

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    //...     

    if (position == 0 && entry_list.size() == 1) {
        view.setBackgroundResource(R.drawable.selector_rounded_corner);
    } else if (position == 0) {
        view.setBackgroundResource(R.drawable.selector_rounded_corner_top);
    } else if (position == entry_list.size() - 1) {
        view.setBackgroundResource(R.drawable.selector_rounded_corner_bottom);
    } else {
        view.setBackgroundResource(R.drawable.selector_middle);
    }
}

希望这有帮助。

关于android listview圆角,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25604700/

相关文章:

android - Android 上的 socket-io httpConnection 内存泄漏

android - 在Android Google V2 map 标记中添加YouTube视频

Android ListViewAnimations - 无法在 DynamicListView 中交换项目

android - ListView 占用所有屏幕空间

android - 许多阵列,一个 ListView ,一个适配器

android - 如何判断主屏幕快捷方式是否存在?

java - 在日期选择器中显示两次的日期

尝试在手机上加载应用程序时出现 Android Studio 0.8.2 错误 "Failure [INSTALL_FAILED_OLDER_SDK]"

android - 如何刷新充满BaseAdapter的Fragment中的ListView?

android - EditText 从 ListView 中的其他 EditText 窃取焦点