下面提到的布局是ListView
中的一个项目的模型。正如你所看到的那样,这三个TextView是分开的,因为每个TextView占据整个行空间的.3
。如何在列表视图中的项目之间添加空间
问题是,当我将项目添加到ListView
时,我发现三个TextView
只是相互关联。例如,假设我要项添加到ListView
包含以下内容:
Adam USA M
我希望看到一些空格分开每个TextView的屏幕上该行,但发生的事情是,我得到的东西像如下:
AdamUSAM
为什么会发生这种情况,以及如何解决它?
model_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="match_parent">
<TextView
android:id="@+id/tvName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".3"
android:text="Name"/>
<TextView
android:id="@+id/tvAddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".3"
android:text="Address: "/>
<TextView
android:id="@+id/tvGender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".3"
android:text="gender: "/>
</LinearLayout>
更新:
现在我改变了布局如下,但问题是挖墙角是,这三个textviews正在出现紧抓住对方没有间距。
布局
<?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="match_parent"
android:orientation="horizontal"
android:weightSum="3">
<TextView
android:id="@+id/tvName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Name: "
android:focusable="false"/>
<TextView
android:id="@+id/tvAddress"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Address: "
android:focusable="false"/>
<TextView
android:id="@+id/tvGender"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="gender: "
android:focusable="false"/>
</LinearLayout>
屏幕截图:
可以共享屏幕截图吗? – Enzokie
@ Enzokie屏幕截图添加 – user2121
至于'xml'布局是好的,你确定你膨胀正确的布局文件? – Pztar