【发布时间】:2016-03-08 10:04:18
【问题描述】:
我有一个列表视图,它是一个包含六个文本视图的线性布局。我希望膨胀文本视图的宽度与父视图匹配,但它的宽度是根据我从数据库获得的值设置的(正在包装)。我在线性布局中给 textview 赋予了相同的权重,但是所有 textview 的宽度都不同。文本视图的值来自使用 JDBC 连接的数据库。
列表视图布局为:
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff">
<ListView
android:id="@+id/lv"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:divider="#0dcd6600"
android:dividerHeight="2dp" >
</ListView>
</HorizontalScrollView>
在列表视图中膨胀的行是:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:background="#ffffff"
android:orientation="horizontal"
android:weightSum="6" >
<TextView
android:id="@+id/txt_date"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/border1"
android:padding="7dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000" />
<TextView
android:id="@+id/txt_sname"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/border1"
android:padding="7dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000" />
<TextView
android:id="@+id/txt_standard"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/border1"
android:padding="7dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000" />
<TextView
android:id="@+id/txt_division"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/border1"
android:padding="7dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000" />
<TextView
android:id="@+id/txt_grno"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/border1"
android:padding="7dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000" />
<TextView
android:id="@+id/txt_rollno"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/border1"
android:padding="7dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000" />
</LinearLayout>
到目前为止,我已经尝试了以下所有选项,但没有任何效果。
- 改变 view = inflater.inflate(R.layout.list_item_attendance,null);
到
view = inflater.inflate(R.layout.list_item_attendance, parent, false); - 使列表视图的宽度匹配父项
- 为所有文本视图制作六个线性布局并使其与父视图匹配。
这是布局不正确的image。文本字段未对齐。
而我想要的就像this。
【问题讨论】:
-
尝试使用表格布局
-
尽量使用Table Layout,让Textview的宽度平分。
-
但是列表视图的相同布局正在其他活动中用于查看报告,我有大约 15 个活动我无法在一天内更改它..我有截止日期..任何其他选项合适吗? @Arvindlal Jaiswal
-
我对这部分感到困惑 -- 我希望膨胀文本视图的宽度与父视图匹配,但它的宽度是根据其中设置的值设置的。 你的意思是,TextViews 的宽度应该足够长,等于父级?还是您的意思是每个 TextView 的宽度都相同? -- 这样它仍然可以水平滚动?
-
如果你没有为你的文本视图设置任何文本。显示正确吗
标签: android listview android-linearlayout