【发布时间】:2014-06-02 19:41:13
【问题描述】:
在我的应用程序屏幕中,我正在使用表格布局。在表格行中,我有两个 textview。第二个 textview 的宽度总是超出屏幕宽度。我尝试了 wrap_content、match_parent 但没有得到如何解决这个问题。如何我将宽度设置为设备屏幕布局宽度?
xml代码-
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:background="@color/even" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="vertical" >
<TableLayout
android:id="@+id/tableLayoutDetails"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TableRow
android:id="@+id/namerow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
>
<TextView
android:id="@+id/nameText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:text="Name" />
<TextView
android:id="@+id/dname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:background="@android:color/black"
android:text="Name :"
android:textColor="#808080" />
</TableRow>
</TableLayout>
</LinearLayout>
</ScrollView>
即使在为 TextView 提供 100dp 宽度后,它也会离开屏幕
【问题讨论】:
-
为什么需要表格行的权重总和,去掉并检查。
-
那个我也试过了,还是一样
-
尝试将线性布局宽度设置为 wrapcontent
-
@amj 试过但没用
-
@yuvaツ 修复您的 TableRow 宽度。 if wrap_content 表示如果 Child 长度增加 Parent 也会增加。
标签: android xml layout textview