Search code examples
javaandroidlistview

Element of listview out of bounds(visually) because of round edges


I am making an android app using Java in android studio. I have defined drawable background for listview with round edges. But last shown row is visually out of listview container. It is not just the line separating it from next record but also "-" symbol can be halfway out of the container. The app looks like this

is there a way to keep content inside the bounds?


Solution

  • It's happening bcz your background is different to listview and list view is always a square layout.

    So basically, use cardview and set app:cardCornerRadius="" to cardview and list view set inside of cardview.

    like this.

    <androidx.cardview.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:cardCornerRadius="10dp"
        >
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            >
            <ImageView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:src="YOUR_BACKGROUND"
                />
            <ListView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                />
        </RelativeLayout>
    </androidx.cardview.widget.CardView>
    

    OR

    The other option is to use a round corner layout. Git link

    and set list view inside of any RoundCornerLayout.