Android 表布局中的文本视图宽度
在我的应用程序屏幕中,我使用了表布局。在表行中,我有两个textview。第二个textview的宽度总是超出屏幕宽度。我尝试了换行内容,匹配父项,但没有找到解决方法。如何将宽度设置为设备屏幕布局宽度 xml代码-Android 表布局中的文本视图宽度,android,xml,layout,textview,Android,Xml,Layout,Textview,在我的应用程序屏幕中,我使用了表布局。在表行中,我有两个textview。第二个textview的宽度总是超出屏幕宽度。我尝试了换行内容,匹配父项,但没有找到解决方法。如何将宽度设置为设备屏幕布局宽度 xml代码- <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_wid
<?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>
即使将文本视图的宽度设置为100dp,它也会退出屏幕,这可能是Android的图形布局问题。我在Android视图设计中检查了你的代码。文本视图字母不会超出布局。如果您有疑问,请将背景设置为文本视图,看看发生了什么?使用此代码:完美工作(用此代码替换您的代码,并根据您的选择进行修改)
请参见此图:
- 在您的情况下,列#0是可以的,因此您只需为列#1启用收缩(如果您愿意,也可以进行拉伸)
<TableLayout ... android:shrinkColumns="1" android:stretchColumns="1" >
- 您可以在主文档中获得完整的解释:
致以最诚挚的问候为什么您需要表格行的权重和,请将其删除并检查。我也尝试了该方法。将线性布局宽度设置为wrapcontent@amj试过但没有working@yuvaツ 固定你的桌子行宽。if wrap_content意味着if Child length increase Parent也将增加。我已经更新了我的图像。将背景设置为文本视图后,它在屏幕宽度内。但是文本仍然超出设备宽度。有什么解决方案吗?我还需要滚动视图。有很多内容简单使用滚动视图…问题是什么
<TableLayout ...
android:shrinkColumns="1"
android:stretchColumns="1" >