2016-11-18 92 views
2

我有下面的XML: -收到骚扰保证金

列表视图: -

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:weightSum="1"> 
    <ListView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/state_listView" 
     android:layout_weight="0.8" 
     android:layout_alignParentLeft="true" 
     android:layout_marginTop="40dp" 
     android:fastScrollEnabled="true" 
     android:layout_toStartOf="@+id/side_index" /> 
    <LinearLayout 
     android:id="@+id/side_index" 
     android:layout_width="50dp" 
     android:layout_marginTop="40dp" 
     android:layout_height="match_parent" 
     android:background="#c3c3c3" 
     android:gravity="center_horizontal" 
     android:orientation="vertical" 
     android:layout_weight="0.2" 
     android:layout_alignParentRight="true"> 
    </LinearLayout> 
</RelativeLayout> 

敌人在列表视图中的每个项目: -

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:weightSum="1" 
    android:background="@drawable/gradient"> 
    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:weightSum="1"> 
     <ImageView 
      android:layout_width="55dp" 
      android:layout_height="49dp" 
      android:id="@+id/legislator_image" 
      android:layout_weight="0.19" 
      android:layout_alignParentLeft="true"/> 
     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:layout_marginLeft="80dp"> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textAppearance="?android:attr/textAppearanceMedium" 
       android:textStyle="bold" 
       android:text="Medium Text" 
       android:id="@+id/firstname" 
       android:layout_marginTop="3dp" /> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textAppearance="?android:attr/textAppearanceSmall" 
       android:text="Small Text" 
       android:id="@+id/details" 
       android:layout_marginTop="3dp" /> 

     </LinearLayout> 

     <ImageView 
      android:layout_width="10dp" 
      android:layout_height="10dp" 
      android:layout_marginTop="20dp" 
      android:layout_marginRight="3dp" 
      android:layout_alignParentRight="true" 
      android:id="@+id/getDetails"/> 
    </RelativeLayout> 
</LinearLayout> 

对于侧指数酒吧: -

<?xml version="1.0" encoding="utf-8"?> 
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/side_list_item" 
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent" 
    android:gravity="center" 
    android:textSize="13sp" /> 

我没有t在任何地方设置保证金,但是在列表视图和侧边栏附近有保证金。我希望列表视图和侧边栏占用整个屏幕而没有任何余量。我附上了一张图片供您参考。 enter image description here

+0

您发布的XML是否显示在片段中?如果是这样,我怀疑父Activity的XML容器可能有一些额外的填充。尝试在包含Activity的内容中查找对填充的任何引用。 – crymson

回答

0

我不确定,它会解决您的问题,也许还有更多的东西,但是它在您的代码中肯定是错误的。

1)当您使用layout_weight,你应该设置layout_width="0dp"(分别为layout_height="0dp"如果父母布局是垂直的),layout_width="0dp"将导致,此属性将被忽略,所以layout_width可以正常工作。

2)第二件事。当您使用layout_weight,你应该在父母的布局设置layout_width到某一定值,你的情况来match_parent而不是wrap_content

There is good explanation

0

更改你相对布局宽度参数(包含ListView控件和LinearLayout中的一个)于:

android:layout_width="match_parent" 

随着android:layout_width="wrap_content"的RelativeLayout的只是它的内容推侧身,所以利润率是不存在的,因为你定义它生长为多,因为它的布局没有得到ENO呃宽度到达边界