0

工作,我不知道为什么我想要做到的是不工作RelativeLayout的利润率不是里面的ListView

相对布局代码:

<?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="wrap_content" 
      android:background="#649760" 
      android:layout_marginRight="30dp"> 

    <ImageView 
     android:layout_width="200dp" 
     android:layout_height="50dp" 
     android:background="#000000"/> 

</RelativeLayout> 

它的外观在Android工作室预览:

Android studio preview. notice the white after the green

注意到白色的绿色权利。

我也是为了去除分频器和控制背景颜色

<?xml version="1.0" encoding="utf-8"?> 
<ListView xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:dividerHeight="0dp" 
     android:divider="@null" 
     android:background="#ffffff"> 
</ListView> 

但什么我得到(从我的手机屏幕捕获)是增加了一个list_view.xml,绿色捕获所有剩余的宽度。

BTW我已经给填充解决它list_view.xml而是因为我在列表中的多个视图,而不是所有的人都应该得到这样的利润率

任何帮助的我不能使用这样的解决方案将不胜感激,并赞许(奖励 - :

Screen capture, no white

回答

2

一个ListView使用AbsListView.LayoutParams的行,当你检查出的文档: http://developer.android.com/reference/android/widget/AbsListView.LayoutParams.html

您可以注意到他们没有任何保证金可用。

因此,解决方法是在你的细胞上添加另一个View,这应该工作:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"> 
    <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="#649760" 
      android:layout_marginRight="30dp"> 

     <ImageView 
       android:layout_width="200dp" 
       android:layout_height="50dp" 
       android:background="#000000"/> 

    </RelativeLayout> 
</LinearLayout> 

的其他解决办法,在你的“rootView”右侧添加视图:

<?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="wrap_content" 
     android:background="#649760"> 

    <View 
      android:layout_width="30dp" 
      android:layout_height="50dp" 
      android:layout_alignParentRight="true" 
      android:background="@color/white"/> 

    <ImageView 
      android:layout_width="200dp" 
      android:layout_height="50dp" 
      android:background="#000000"/> 

</RelativeLayout> 

我知道这不是最好的表现,但它是我找到的唯一解决方法。

+0

是啊,你的解决方案的工作原理和我已经实现了它(但是,而不是LinearLyaout我已经使用相对布局),但现在我有2个嵌套布局在列表布局,我想这是一个矫枉过正。我的问题更多的是为什么它不起作用( - : – royB

+0

回答编辑,希望它会帮助你。 – Andros

+0

再次感谢您的答案( - :我没有给listView的任何保证金/填充,只对relativeLayout视图。这就是为什么我很惊讶它没有工作 – royB