Reputation: 2243
i try to create rounded corners listview.i created custom xml file and i wrote this code
<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
this is a my custom listview adapter code
<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>
how i can solve my problem? if anyone knows solution please help me thanks
Upvotes: 2
Views: 156
Reputation: 28823
Check this. In that middle entries use different style, so only first and last rows are applied top and bottom round corners respectively. This might help you achieve what you need.
So what you will need to do is:
Simply apply your rounded corner style xml if the item position is first or last.
@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);
}
}
Hope this helps.
Upvotes: 3
Reputation: 3359
replace your
<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>
via
<ListView
android:id="@+id/cat_listview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:dividerHeight="1dp"
android:background="@drawable/customshape"
android:listSelector="@drawable/list_selector" >
</ListView>
Upvotes: 1