Android的TableLayout宽度问题 [英] Android TableLayout width issue

查看:123
本文介绍了Android的TableLayout宽度问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用TableLayout显示数据。
当活动调用的onCreate()。右列的TextViews的文本会被设为

现在,你可以在下面的图片中所看到的,我的地址文本可能会很长,它应该被包装。
所以我设置的android:layout_width =WRAP_CONTENT。但它仍然需要屏幕尺寸的宽度来包装数据。
我怎样才能从这个问题的解决?

我的XML:

 <?XML版本=1.0编码=UTF-8&GT?;
< TableLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    机器人:填充=5像素>
    <&的TableRow GT;
        <的TextView的android:文本=#作业
            机器人:paddingRight =5像素/>
        < TextView的机器人:ID =@ + ID / DetailJobNo/>
    < /&的TableRow GT;
    <&的TableRow GT;
        <的TextView的android:文本=地址
            机器人:paddingRight =5像素/>
        < TextView的机器人:ID =@ + ID / DetailAddress
            机器人:layout_width =WRAP_CONTENT
            机器人:文字=地址地址地址地址地址地址地址地址/>
    < /&的TableRow GT;
< / TableLayout>


解决方案

添加的android:shrinkColumns =1来TableLayout解决了我的问题。

I'm using TableLayout to display data. Text of the TextViews of the right column will be set when activity calls onCreate().

Now, as you can see in the following image that my address text can be long and it should be wrapped. So I set android:layout_width="wrap_content". but it still take a width of screen size to wrap data. How can I overcome from this issue?

My xml:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="5px">
    <TableRow>
        <TextView android:text="Job#"
            android:paddingRight="5px" />
        <TextView android:id="@+id/DetailJobNo" />
    </TableRow>
    <TableRow>
        <TextView android:text="Address"
            android:paddingRight="5px" />
        <TextView android:id="@+id/DetailAddress"
            android:layout_width="wrap_content"
            android:text="Address Address Address Address Address Address Address Address "/>
    </TableRow>
</TableLayout>

解决方案

Adding android:shrinkColumns="1" to TableLayout solves my issue.

这篇关于Android的TableLayout宽度问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆