0

This is probably something simple, but I couldn't get it right. I am using a custom list fragment and I am trying to add some margin to it. Here's my xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/rounded_courner" >

    <TextView
        android:id="@+id/textViewProductName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:text="TextView" />

    <ImageView
        android:id="@+id/imageViewProductPic"
        android:layout_width="250dp"
        android:layout_height="250dp"
        android:layout_below="@+id/textViewProductName"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="16dp"
        android:src="@drawable/counter_bg" />

    <TextView
        android:id="@+id/textViewProductPrice"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/imageViewProductPic"
        android:layout_centerHorizontal="true"
        android:text="TextView" />

</RelativeLayout>

and the outcome is the outcome

Now I would like to add margins on the top right bottom left. So the borders aren't so stick to the sides and to each other. I've try doing this

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="30dp"
    android:layout_marginRight="30dp"
    android:layout_marginTop="30dp"
    android:layout_marginBottom="30dp"
    android:background="@drawable/rounded_courner" >

But it doesn't work. Here's the outcome:enter image description here

Does anyone has any idea to achieve the margin in my case? Thank you in advance for your help.

Charles
  • 50,943
  • 13
  • 104
  • 142
user1817517
  • 349
  • 1
  • 5
  • 16
  • Perhaps your ImageView `layout_(width|height)` dimensions are the culprit. Set it to `wrap_content` and its `scaleType` attribute to `FIT_XY` – Vino Feb 23 '14 at 09:17
  • Change your width of Relative Layout to match_parent. – Piyush Feb 24 '14 at 04:43

2 Answers2

0

Maybe try using placing a divider in the ListView xml layout?

Also this question might be useful: Spacing between listView Items Android

Community
  • 1
  • 1
Ben S
  • 33
  • 8
  • Hi, Thank you for your reply. The problem is I am using a listFragment And I attach to activity programmatically. There's no such tag – user1817517 Feb 23 '14 at 19:03
0

OK I figure it out. Just in case anyone that looking for the same solution.

In my ListFragment

 @Override
  public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    setListAdapter(productListAdapter);
    //this is necessary to avoid unwanted gap colors 
    getListView().setDivider(null); 
    getListView().setDividerHeight(30);
    getListView().setPadding(15, 0, 15, 0);
    getListView().setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
  }
user1817517
  • 349
  • 1
  • 5
  • 16