The question is: There is a RelativeLayout markup inside which the ListView is located with indents at the edges. So when filling the list, the ListView has a naturally rectangular shape, which purely aesthetically does not satisfy me!

I wanted to find out how to round the edges of the ListView on Android. Thank you in advance!

  • Do not make iOS from Android, follow the guidelines. And by sabzh - android: background + shape drawable. - falstaf
  • In this case, the edges of all the ListView elements will be rounded, and I want to round the edges of the container only! The rounding is not my whim, but the designer's fabrications clinched with the signature of the customer! And the designers never seemed to leave the iPhones! The whole design under the iyos and I have to adjust it for the android! - vanyamelikov
  • So you also apply background to the ListView itself, and not to its elements. And about the designers - a painfully familiar situation. :) - falstaf
  • Well, I apply to him! When you click on the top element in this version, the background of the element kills the background of the ListView, and if you apply it to the background image in the version with the ListView element not pressed, it automatically kills the main background, in the sense of cluttering! - vanyamelikov

3 answers 3

Try wrapping the ListView with some Layout and assign it the desired background . For ListView , you can put android:cacheColorHind in @android:color/transparent .

    I also don’t welcome you to make an apple out of Andrew, but you have to ....

    In your case, I do this:

    There are 4 image files for the background of the ListView cell: for the center cell, for the top one, for the bottom one, for the case when the cell is only 1 (it has all 4 edges rounded off). the last 3 with rounded edges (in fact, the pictures themselves are rectangular, just around the edges of the alpha channel, therefore, a rounding effect is created)

    In the adapter, I programmatically in the getView method, knowing the position of the current element and the total number of elements in the list, I set the necessary background to the view.

    • That's exactly what I do not know the number of elements, because foliage is filled from an array of parsed jason file. You can of course put the operator who will calculate by url Lenf and issue! But all this is again work with drawable resources! Is it really impossible to change the shape of the container itself? - vanyamelikov
    • how do you not know the number of elements in the array? and the adapter method getCount () why then? I remember in my time I smoked this topic intensively and as a result I came only to this decision, since it ideally gives the desired result. - Roman Zakharov

    Use CardView from support-v7: 21 from Google. Use CardView as a container list.

    In CardView, you can set the rounding angle.

     <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:card_view="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="wrap_content" card_view:cardBackgroundColor="?cardBackGroundColor" card_view:cardCornerRadius="6dp" card_view:cardElevation="5dp" > </android.support.v7.widget.CardView>