簡體   English   中英

文本視圖在表格布局中走出屏幕

[英]Textview going out of screen in tablelayout

我是 android 新手,我使用了 TableLayout,我從字符串數組中向其中添加了兩列數據。 但是我的第二列從屏幕上消失了。 似乎我的第二列的所有條目都從第一列中最長條目結束的地方開始。 如何使兩列都適合屏幕,兩列的寬度都為 50%?

我的代碼是這樣的..

@Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.findia1);

        TableLayout tl = (TableLayout) findViewById(R.id.tablay1);

        for (int i = 0; i < s1.length; i += 2) {
            TableRow tr1 = new TableRow(this);
            tr1.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT));

            TextView textview1 = new TextView(this);
            textview1.setText(s1[i]);
            tr1.addView(textview1);

            TextView textview2 = new TextView(this);
            textview2.setText(s1[i+1]);
            tr1.addView(textview2);

            tl.addView(tr1, new TableLayout.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));


        }

xml代碼是

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TableLayout
        android:id="@+id/tablay1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
         >

    </TableLayout>

</LinearLayout>

我想我得到了答案..我用過

tl.setColumnShrinkable(0, true); tl.setColumnShrinkable(1, true);

這樣就可以了!

為 TextView 賦予權重android:layout_weight="1"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM