1

我在android中使用java設計了一個動態表。該表有3列,但最後一列顯示數據出/離屏幕,但屏幕上不可見,但在那裏。TableLayout在Android中的行和列使用java


我怎樣才能使第三列的數據繼續低於它的顯示,使所有數據是對用戶可見?


這是用於實現的Java代碼IV:

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

+0

你能分享你的xml佈局嗎? – Daniel

+0

Iv更新了代碼Daniel .. Infact我需要跨越行並將第三個數據放入單元格本身,並避免將數據隱藏在屏幕外。 – Gerrard

回答

0

看看setColumnShrinkable()official doc。這將縮小您的列以使其適合屏幕。

另外,如果設備處於橫向模式(因爲列可能不夠寬),請在official doc處查看setColumnStrechable()以生成列strech。讓我知道它是如何工作的。

+0

謝謝mate..i會嘗試,讓你知道很快.. – Gerrard

+0

不客氣:) – Daniel