2014-05-01 52 views
0

我正在爲每行創建一個包含圖像,文本和複選框的列表。我使用Table Layout,但我想將複選框的位置移動到右側,gravity:right沒有工作。我能爲此做些什麼? 代碼:右側列表中的Android複選框

<?xml version="1.0" encoding="utf-8"?> 
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 
    <TableRow> 
     <ImageView 
      android:id="@+id/img" 
      android:layout_width="50dp" 
      android:layout_height="50dp"/> 

     <TextView 
      android:id="@+id/txt" 
      android:layout_width="wrap_content" 
      android:layout_height="50dp" /> 

     <CheckBox 
      android:id="@+id/checkBox1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginRight="20dp" 
      android:text="" 

      /> 

</TableRow> 
</TableLayout> 
+0

嘗試設置CheckBox的權重。 –

+0

非常感謝你,它的工作 – user3553928

+0

@JagdeepSingh請爲此寫一個答案,只要你做好評論我的回答,我會刪除它 –

回答

0

您將需要設置複選框

的重量所以,現在你的代碼是:由Jagdeep Singh給出

<?xml version="1.0" encoding="utf-8"?> 
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 
    <TableRow> 
     <ImageView 
      android:id="@+id/img" 
      android:layout_width="50dp" 
      android:layout_height="50dp"/> 

     <TextView 
      android:id="@+id/txt" 
      android:layout_width="wrap_content" 
      android:layout_height="50dp" 
      android:gravity="center_vertical" 
      /> 

     <LinearLayout 
     android:id="@+id/linearLayout1" 
     android:layout_width="wrap_content" 
     android:gravity="right" 
     android:layout_weight="0.08" 
     android:layout_height="fill_parent" > 

      <CheckBox 
       android:id="@+id/checkBox1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:gravity="center_vertical" /> 

    </LinearLayout> 

</TableRow> 

</TableLayout> 

答案。 注:我刪除了問題的答案,所以我不得不把它放在這裏。但我會盡快刪除此Jagdeep寫回答,我被告知

+0

你提出這個問題...你應該評論,所以實際上提出這個解決方案的人可以得到它的榮譽。如果他們沒有迴應,您可以隨時回覆並將其作爲答案發布,就像您一樣。這只是剽竊。 –

+1

@ChrisWesseling對不起,我只是那樣做 –

+0

@DakshShah你的回答是完美的,我剛剛給了user3553928這個想法,以便他/她可以搜索和應用這個問題。 –