简体   繁体   English

tableRow条目不显示在屏幕上

[英]tableRow entries go off screen

I am using a table layout to show information based on a user specifications. 我正在使用表格布局来显示基于用户规范的信息。 The user enters data into a database, then this data is taken and displayed on a table were each row has 3 textView entries. 用户将数据输入数据库,然后获取该数据并将其显示在表上,每行有3个textView条目。 The problem is that if the data entered by the user is to long, it goes off screen and is not visible. 问题是,如果用户输入的数据太长,它将离开屏幕并且不可见。 Any ideas? 有任何想法吗? The code I used to do this is below: 我用来执行此操作的代码如下:

xml XML

<TableLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:stretchColumns="*"
    android:id="@+id/tl">
<TableRow
        android:id="@+id/tableRow1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="1dp" >

        <TextView
            android:id="@+id/timeCol"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Time"
            android:textSize="20sp"
            android:textStyle="bold"
            android:textColor="#FF0000"/>

        ....

    </TableRow>          
</TableLayout>

Java Java的

 for (final String time : timesArray) 
    {
        i++;
        TableRow row1= new TableRow(this);

        event = db.getEvent(i, gameId);
        player = db.getPlayer(i, gameId);

        TextView timeRow = new TextView(this);
        TextView playerRow = new TextView(this);
        TextView eventRow = new TextView(this);

        timeRow.setText(time);
        timeRow.setTextColor(Color.WHITE);
        playerRow.setText(player);
        playerRow.setTextColor(Color.WHITE);
        eventRow.setText(event);
        eventRow.setTextColor(Color.WHITE);

        row1.addView(timeRow);
        row1.addView(playerRow);
        row1.addView(eventRow);

        tl.addView(row1);  
    }

And it looks like this if the data is too long 如果数据太长,看起来像这样 在此处输入图片说明

SOLUTION! 解!

Setting layout_width to 0 and then assigning layout_weight to a float based on the amount of the screen you want a column to take up (For example, 0.5 would let the column take up half the screen) allows all the information to be shown on the screen. 将layout_width设置为0,然后根据您希望一列占用的屏幕数量将float_weight分配给一个浮点数(例如,如果0.5则该列占据整个屏幕的一半),则可以在屏幕上显示所有信息。 The code to do this is below. 下面是执行此操作的代码。

XML XML

<TableLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/tl">

    <TableRow
        android:id="@+id/tableRow1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="1dp" >

        <TextView
            android:id="@+id/timeCol"
            android:layout_width="0px"
            android:layout_weight="0.2"
            android:layout_height="wrap_content"
            android:text="Time"/>

        <TextView
            android:id="@+id/playerCol"
            android:layout_width="0px"
            android:layout_weight="0.4"
            android:layout_height="wrap_content"
            android:text="Player"/>

        <TextView
            android:id="@+id/eventCol"
            android:layout_width="0px"
            android:layout_weight="0.4"
            android:layout_height="wrap_content"
            android:text="Event"/>

    </TableRow>          

java java的

TableLayout tl = (TableLayout) findViewById(R.id.tl);
TableRow row1= new TableRow(this);

TextView timeRow = new TextView(this);
TextView playerRow = new TextView(this);
TextView eventRow = new TextView(this);

TableRow.LayoutParams text1Params = new TableRow.LayoutParams();
        text1Params.width = 0;
        text1Params.weight = (float) 0.2;
        TableRow.LayoutParams text2Params = new TableRow.LayoutParams();
        text2Params.weight = (float) 0.4;
        text2Params.width = 0;
        TableRow.LayoutParams text3Params = new TableRow.LayoutParams();
        text3Params.weight = (float) 0.4;
        text3Params.width = 0;

        timeRow.setLayoutParams(text1Params);
        playerRow.setLayoutParams(text2Params);
        eventRow.setLayoutParams(text3Params);

        row1.addView(timeRow);
        row1.addView(playerRow);
        row1.addView(eventRow);

        tl.addView(row1, params);  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM