Sandah Aung
Sandah Aung

Reputation: 6188

Android rounded corners in rectangles have ugly edges that show up when pressed

The following is my ListView with a background. List items when pressed are showing unwanted areas at upper right and lower right corners. I want them to disappear. What can I do?

ugly edges in rectangles with rounded corners

I have attached the XML code for the background here:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:right="15dp">
        <shape android:shape="rectangle" >
            <solid android:color="#6bb726" />
            <size android:width="3dp" android:height="0dp" />
        </shape>
    </item>
    <item  android:left="5dp">
        <shape android:shape="rectangle" >
            <solid android:color="#aaaaaa" />
            <corners
                android:bottomLeftRadius="0.1dp"
                android:bottomRightRadius="15dp"
                android:topLeftRadius="0.1dp"
                android:topRightRadius="15dp" />
        </shape>
    </item>
    <item android:left="5dp" android:top="2dp" android:bottom="2dp" android:right="2dp">
        <shape android:shape="rectangle">
            <gradient
                android:type="radial"
                android:centerX="150%"
                android:centerY="50%"
                android:startColor="#999999"
                android:endColor="#eeeeee"
                android:gradientRadius="100"/>
            <corners
                android:bottomLeftRadius="0.1dp"
                android:bottomRightRadius="12dp"
                android:topLeftRadius="0.1dp"
                android:topRightRadius="12dp" />
        </shape>
    </item>
</layer-list>

ListView layout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ListView
        android:id="@+id/denko_station_list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        android:layout_marginTop="50dp"
        android:divider="@android:color/transparent"
        android:dividerHeight="10dp" />

</RelativeLayout>

Upvotes: 1

Views: 84

Answers (2)

Rathan Kumar
Rathan Kumar

Reputation: 2577

just add the following line in listview layout code:

android:listSelector="@android:color/transparent"

like below

       <ListView
        android:id="@+id/lvId"
        android:layout_width="match_parent"
        android:listSelector="@android:color/transparent"
        android:layout_height="match_parent"/>

Upvotes: 2

Piyush
Piyush

Reputation: 18933

Set

android:listSelector="@android:color/transparent"

for your listView in xml file.

Upvotes: 1

Related Questions