How to set background of listview?

后端 未结 2 1211
说谎
说谎 2021-01-16 16:08

I have a ListView in one of my activity. I have one customview which is created extending ImageView.I want to add this customview as background of

2条回答
  •  时光说笑
    2021-01-16 16:52

    You cannot use your custom View as Background of ListView. However a workaround could be:

    • Use RelativeLayout as parent layout container.
    • Add a LinearLayout with property of fill_parent for both width and height
    • Give any id as list_background to the LinearLayout.
    • Then add the ListView to the parent RelativeLayout.
    • Add property android:layout_centerInParent="true" to both of the ListView and LinearLayout
    • Remove background of the ListView and your CustomRow if you have any.
    • Now get the LinearLayout in Java and add the View to that LinearLayout

提交回复
热议问题