[英]Getting unwanted margin
我有以下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" />
我没有在任何地方设置边距,但是在列表视图和边栏附近有一个边距。 我希望listview和侧边栏占据整个屏幕,而没有任何边距。 我已附上一张图片供您参考。
我不确定,它是否可以解决您的问题,也许还有其他问题,但这在您的代码中绝对是错误的。
1)使用layout_weight
,应设置layout_width="0dp"
(如果父布局是垂直的,则分别设置layout_height="0dp"
), layout_width="0dp"
将导致该属性被忽略,因此layout_width
可以正常工作。
2)第二件事。 使用layout_weight
,应将父布局中的layout_width
设置为某个确定的值,在这种情况下,应设置为match_parent
而不是wrap_content
将您的相对布局(包含ListView和LinearLayout的一个)的宽度参数更改为:
android:layout_width="match_parent"
使用android:layout_width="wrap_content"
,RelativeLayout只会随着其内容向侧面推动而增长,因此没有边距,因为您定义了它,这是因为Layout的宽度不足以到达边界
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.