0

I have an Activity that includes a ListFragment in the activity's xml file...

<fragment
    android:id="@+id/shoppingListNamesFragment"
    android:name="com.example.ShoppingListNamesFragment"
    android:layout_below="@id/shoppingListsTitle"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

I would like to put a border around this fragment. I have tried adding this to the above XML...

android:background="@drawable/white_dashed_border"
    android:padding="14dp"
    android:layout_margin="14dp"

...but it doesn't create the border (whereas it does create a border if I add those 3 lines to the xml, for example, to a LinearLayout).

How do I add a border to the ListFragment (ideally by using xml)?

PS - There is a similar question here which suggests adding a parent layout, but I want to avoid that if possible.

Community
  • 1
  • 1
ban-geoengineering
  • 15,533
  • 18
  • 140
  • 225
  • You'd need to put the border on the root element of the fragments layout AFAIK – Broak Nov 04 '14 at 16:00
  • 1
    Do you have access to change the code of the ShoppingListNamesFragment fragment, or it is in a library that you have no control over? If you can change the code, you can have a custom theme you can apply just to that fragment that adds the border (shape drawable) as a background. Take a look at this: http://stackoverflow.com/questions/9469174/set-theme-for-a-fragment – Dimitar Darazhanski Nov 04 '14 at 16:35

2 Answers2

0

Add the border to the root element of your ListFragment's layout xml:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/white_dashed_border"
    android:padding="14dp"
    android:layout_margin="14dp">
JstnPwll
  • 8,682
  • 2
  • 29
  • 55
0

This solution may help you very easily, as well for this specific case (fragment) as for any widget. It enables you to wrap any widget you want inside a pre-made and configurable bordered Framelayout.

Community
  • 1
  • 1
PAD
  • 2,010
  • 1
  • 20
  • 27