Android 无法使边距为的自定义listview正常工作

Android 无法使边距为的自定义listview正常工作,android,android-layout,android-listview,Android,Android Layout,Android Listview,这可能很简单,但我做不好。我正在使用一个自定义列表片段,并试图为其添加一些边距。这是我的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

这可能很简单,但我做不好。我正在使用一个自定义列表片段,并试图为其添加一些边距。这是我的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>
结果是

现在我想在右上角和左下角添加边距。因此,边界不会如此紧密地贴在两边和彼此之间。我试过这么做

<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" >
但它不起作用。结果如下:

在我的情况下,有人有什么想法来获得利润吗?
提前感谢您的帮助。

是否可以尝试在ListView xml布局中放置分隔符

这个问题也可能有用:

好的,我想好了。以防万一,任何人都在寻找相同的解决方案

在我的列表片段中

 @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);
  }

可能是您的ImageView布局|宽度|高度尺寸造成的。将其设置为wrap_content,并将其scaleType属性设置为FIT_xy更改相对布局的宽度以匹配_parent。您好,感谢您的回复。问题是我正在使用一个listFragment,并且以编程方式附加到活动。没有这样的标签