2016-11-08 16 views
2

目前我正在開發一些android應用程序,其中包含list。 我已經在移動(手機)設備中製作了一個。 ,我想在平板電腦(7「-10」)顯示屏上顯示responsive。所以headercolumn看起來與移動顯示器相同。如何使TableLayout響應

這裏是5" 和7" 顯示之間,差別很大:

5" display

Tablet Dispaly

這是我當前的XML代碼

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" android:layout_height="match_parent" 
android:tag="reqtag" 
> 
<TableLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <TableRow 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:showDividers="beginning|end" 
     android:layout_marginLeft="5dp" 
     android:layout_marginRight="5dp" 
     android:layout_marginTop="10dp" 
     android:layout_marginBottom="10dp"> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:text="Date" 
      android:id="@+id/tvClaimDateReimbursementRequest" 

      android:layout_marginRight="50dp" 
      android:textSize="12dp" 
      android:width="100dp" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:text="Type" 
      android:textSize="12dp" 
      android:layout_marginLeft="50dp" 
      android:layout_marginRight="50dp" 
      android:id="@+id/tvTypeRequestReimbursement" 
      android:width="80dp" /> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:text="Amount" 
      android:textSize="10dp" 
      android:layout_marginLeft="50dp" 
      android:layout_marginRight="50dp" 
      android:width="100dp" 
      android:id="@+id/tvAmountReimbursementRequest" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:text="Status" 
      android:textSize="12dp" 
      android:layout_marginLeft="50dp" 
      android:layout_marginRight="50dp" 
      android:id="@+id/tvStatusReimbursementRequest" /> 
    </TableRow> 
</TableLayout> 

我已經看到這裏的文檔https://developer.android.com/guide/practices/screens_support.html

但我還是不明白, 是否有任何最佳做法來做這樣的事情?

感謝

+0

變化的線性佈局表:我想補充一個父linenar佈局(垂直)和內:線性佈局(垂直)和下這個線性佈局,recyclerview。 Stas Melnychenko說,爲了讓它響應,使用重力。刪除邊距,提供更大的文本大小,並使用strings.xml添加文本:不要對文本進行合併,如果需要維護代碼,則無用。 – Jaco

回答

2

你可以嘗試設置

android:layout_width="0dp" 
android:layout_weight="1" 

爲每頭TextView,因爲TableRowLinearLayout。我相信TableView不是最好的方法。如果你描述你想達到什麼目的,我們可以找出更好的方法。

0

指定您的表格佈局a權重..然後分配並將該權重分配給所有textviews。像:

<TableRow 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:weight_sum="1" > 

<TextView 
      android:layout_width="0dp" 
      android:layout_weight=".2" // for five texts .2 for each 
      android:layout_height="wrap_content" 
      ...... /> 
0

您的錶行 是水平排列其子佈局在嘗試此代碼。 TableRow應始終用作TableLayout的子項。如果TableRow的父級不是TableLayout,則TableRow將表現爲水平LinearLayout。

TableRow的子元素不需要在XML文件中指定layout_width和layout_height屬性。 TableRow總是強制這些值分別爲MATCH_PARENT和WRAP_CONTENT。