java - Android 中的 TableLayout 行和列与 java

标签 java android android-layout android-linearlayout android-tablelayout

我用java在android中设计了一个动态表。该表有 3 列,但最后一列显示屏幕外/屏幕外的数据,这些数据在屏幕中不可见,但确实存在。

<小时/>

如何让第三列的数据继续显示在其下方并让所有数据对用户可见?

<小时/>

这是用于实现该目的的 java 代码:

LinearLayout main_layout = (LinearLayout) findViewById(R.id.main_layout);

    TableLayout table_service = new TableLayout(this);
    table_service.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

    for(ServiceArray s : arr_service){

        TableRow tr_item = new TableRow(this);
        tr_item.setLayoutParams(new TableLayout.LayoutParams(
                LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT
                ));

        TextView date = new TextView(this);
        date.setText(s.getDateOfService());
        date.setTextColor(Color.WHITE);
        date.setLayoutParams(new TableRow.LayoutParams(
                LayoutParams.FILL_PARENT, LayoutParams.MATCH_PARENT
                ));
        date.setBackgroundColor(Color.RED);

        TextView mileage = new TextView(this);
        mileage.setText(s.getMileage());
        mileage.setTextColor(Color.WHITE);
        mileage.setLayoutParams(new TableRow.LayoutParams(
                LayoutParams.FILL_PARENT, LayoutParams.MATCH_PARENT
                ));
        mileage.setBackgroundColor(Color.BLUE);

        TextView description = new TextView(this);
        description.setText(s.getDescription());
        description.setTextColor(Color.WHITE);
        description.setLayoutParams(new TableRow.LayoutParams(
                LayoutParams.FILL_PARENT, LayoutParams.MATCH_PARENT
                ));
        description.setBackgroundColor(Color.GREEN);

        tr_item.addView(date);
        tr_item.addView(mileage);
        tr_item.addView(description);

        table_service.addView(tr_item);
    }


    main_layout.addView(table_service);
    setContentView(main_layout);
<小时/>

xml 在这里:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/main_layout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    tools:context=".DisplayMessageActivity" >

</LinearLayout>
<小时/>

图片here

最佳答案

看看 official doc 处的 setColumnShrinkable() 。这将缩小您的列以使其适合屏幕。

此外,请查看 official doc 处的 setColumnStrechable()如果设备处于横向模式,则使列拉伸(stretch)(因为列可能不够宽)。让我知道它是如何工作的。

关于java - Android 中的 TableLayout 行和列与 java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22720953/

相关文章:

android - 不按 "back"按钮返回

java浮点精度(0.1+0.2+...+1.00 ..or.. 1.00+0.99+0.98+...+0.1)

java - JTable 行排序而不更改 "Sl No"列

java - 持久化的序列化缺点

android - FrameLayout 与 NestedScrollView 的高度不匹配

android - 不调用getDrawable方法检查ImageView是否有图片

android - 左侧按钮和可绘制对象

java数组 boolean 复制没有引用

android - 资源链接

android - 将输入流转换为文件android