Android表格布局格式化问题

sam*_*bar 25 android tablelayout

when the text cell is large尽管有文字包装,但我无法让我的TableLayout适合屏幕内部inside the cell.

这是我的TableLayout.一个简单的两行,两列表.左列细胞是multiline.如果其中一个单元格的文本很大,则需要在两行中断,该列将被拉伸以填满整个屏幕,并且右列被推出屏幕.

为什么?如何强制全桌留在屏幕内?任何提示都受到欢迎.

我的TableLayout如下:

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/myTableLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TableRow>
    <TextView
        android:text="Account 4 with a very large name to see if it breaks  on two or more lines"
        android:singleLine="false"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        >
    </TextView>
    <TextView
        android:text="$400.00"
        android:gravity="right"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        >
    </TextView>
</TableRow>

<TableRow>
    <TextView
        android:text="Account 5"
        android:singleLine="false"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        >
    </TextView>
    <TextView
        android:text="$400.00"
        android:gravity="right"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        >
    </TextView>
</TableRow>

</TableLayout>
Run Code Online (Sandbox Code Playgroud)

显示布局的代码是基本的:

public class AccountBrowserTest 
    extends Activity
{
    public void onCreate(Bundle savedInstanceState) 
    {    
        super.onCreate(savedInstanceState);

        this.setContentView(R.layout.accountbrowser_test);

    }
} 
Run Code Online (Sandbox Code Playgroud)

Pau*_*aul 36

添加机器人:stretchColumnsandroid:shrinkColumnsTableLayout元素:

<TableLayout
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:stretchColumns="1"
  android:shrinkColumns="1">
Run Code Online (Sandbox Code Playgroud)

1值是要发生变化的列.您可以指定多个这样的值:

android:stretchColumns="0,1"
Run Code Online (Sandbox Code Playgroud)

或者如果您希望更改发生在所有列上,如下所示:

android:stretchColumns="*"
Run Code Online (Sandbox Code Playgroud)

请在此处查看详细信息:http://android-pro.blogspot.com/2010/02/table-layout.html


Jon*_*oth 8

我的应用程序遇到了同样的问题,并找到了以下解决方案:

<TableLayout 
   android:shrinkColumns="0"
   android:stretchColumns="1" 
   android:layout_width="match_parent"
   android:layout_height="wrap_content">
</TableLayout>
Run Code Online (Sandbox Code Playgroud)

这适用于2列.


Jeb*_*Jeb 6

我有同样的问题,并通过添加解决它

android:stretchColumns="0"
Run Code Online (Sandbox Code Playgroud)

到TableLayout元素和设置

android:layout_width="0dp"
Run Code Online (Sandbox Code Playgroud)

在TextView上太长了.

  • 这究竟是什么意思?你怎么知道这是解决方案? (2认同)

Muh*_*eeb 5

在表格布局中,对于希望允许它们缩小以适合的列,使用shrinkColumns属性

最简单的方法是:

<TableLayout
android:shrinkColumns="*"/>
Run Code Online (Sandbox Code Playgroud)

缩小所有列,或者您可以编写而不是"*",即要缩小的列索引,在您的情况下将是

<TableLayout
android:shrinkColumns="0,1"/>
Run Code Online (Sandbox Code Playgroud)

请注意,列索引从零开始,因此最新代码允许第一个(index = 0)和第二个(index = 1)列缩小.