2016-06-21 189 views
0

我正在使用tablelayout,其中每行都有一些複選框,並且正在使用自定義適配器。這些列在整個屏幕上均勻展開。在父級佈局中,我還有一系列「檢查/取消全選」類型複選框,並且它們與列表視圖複選框完美對齊。我的問題是,我無法獲得複選框的列標題以與列對齊。他們有一個蠕變,無論是太多或太少,更不用說在手機和平​​板電腦設備上工作。我懷疑這個問題可能是由與最左邊的複選框相關的文本引起的,唯一的文本與它們有任何關聯。對齊自定義列表視圖複選框的列標題

這是用於檢查/取消選中所有複選框和排隊的xml。

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <TableLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@color/light_blue" 
     android:orientation="horizontal"> 

     <TableRow 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 

      <CheckBox 
       android:id="@+id/checkBox1" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:width="60dp" 
       android:background="@color/light_blue" 
       android:focusable="false" 
       android:focusableInTouchMode="false" 
       android:text="Ck all" 
       android:textSize="15dp" 
       android:textStyle="bold" /> 
      <CheckBox 
       android:id="@+id/checkBoxI" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:background="@color/light_blue" 
       android:focusable="false" 
       android:focusableInTouchMode="false" /> 

      <CheckBox 
       android:id="@+id/checkBoxII" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:background="@color/light_blue" 
       android:focusable="false" 
       android:focusableInTouchMode="false" /> 

這是列標題和不排隊。

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <TableLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@color/light_blue" 
     android:orientation="horizontal"> 

     <TableRow 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 

      <TextView 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:width="60dp" 
       android:gravity="center" 
       android:background="@color/light_blue"/> 
      <TextView 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:background="@color/light_blue" 
       android:gravity="center" 
       android:text="I"/> 
      <TextView 
       android:layout_height="match_parent" 
       android:gravity="center" 
       android:layout_weight="1" 
       android:background="@color/light_blue" 
       android:text="I"/> 

這是一個也沒有排隊的又一次嘗試。

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <TableLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@color/light_blue" 
     android:orientation="horizontal"> 

     <TableRow 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 

      <TextView 
       android:layout_height="match_parent" 
       android:width="60dp" 
       android:layout_weight="1" 
       android:text="" 
       android:gravity="center" 
       android:background="@color/light_blue" 
       android:focusable="false" 
       android:focusableInTouchMode="false"/> 
      <TextView 
       android:id="@+id/keycode" 
       android:layout_height="match_parent" 
       android:gravity="center" 
       android:layout_weight="1" 
       android:background="@color/light_blue" 
       android:text="I" 
       android:textStyle="bold" /> 

      <TextView 
       android:layout_height="match_parent" 
       android:gravity="center" 
       android:layout_weight="1" 
       android:background="@color/light_blue" 
       android:focusable="false" 
       android:focusableInTouchMode="false" 
       android:text="II" 
       android:textStyle="bold" /> 

我試過文本對齊的許多不同的組合,甚至試圖強行列寬這當然不會跨設備使用。我花了整整一天的時間,仍然沒有線索。任何幫助讚賞。

回答

0

好的,這是我的愚蠢。我忘記了我正在剪切和粘貼時將LinearLayouts放在表格行周圍。刪除這些Linearlayouts後,事情如預期一樣排列。我確實必須給第一列一個textsize parm,否則與最左邊的複選框相關聯的文本的可變寬度會混淆其餘列的對齊。我只需要使文本大於該列中的任何文本。