我在Android studio的列表視圖中創建了一個表格視圖(參見下面的代碼),並且出於各種原因,我使用了文本視圖和複選框作爲單獨的元素,而不是隻是有複選框並附上文本。問題是文本位於屏幕/表格的左側,但複選框基本居中,因爲我希望它位於最右側。Android studio移動複選框到表單元格右邊
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/title"
android:layout_above="@+id/Button1"
android:id="@+id/scrollView"
android:background="@drawable/list">
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableRow
android:layout_width="fill_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/Maths"
android:id="@+id/Maths"
android:layout_column="1"
android:textColor="#ffffff" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/MathsCheck"
android:layout_column="2"
android:buttonTint="#00ffff"
android:onClick="MathsClicked"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/History"
android:id="@+id/History"
android:layout_column="1"
android:textColor="#ffffff"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/HistoryCheck"
android:layout_column="2"
android:onClick="HistoryClicked"
android:buttonTint="#00ffff" />
</TableRow>
</TableLayout>
</ScrollView>
實際上有很多這些文本視圖和複選框,但你明白了。我曾嘗試使用填充和邊距,但這並不能真正起作用,因爲它在某些設備顯示器上可以正常工作,但我必須對其進行硬編碼,這並不理想。我也嘗試過由於某種原因似乎沒有任何作用的重力功能。
任何幫助表示讚賞
我的意思是肯定和否,對我來說實現我想用垂直線性佈局實現的設計是可行的,事情是我可能希望將來在一個textview旁邊添加幾個複選框並且具有一些文本視圖比如有3個複選框,有些是1,但是第三個複選框總是需要對齊,所以我選擇了表格佈局。 –
您提到的場景仍然可以使用RelativeLayouts實現。我會相應地編輯我的答案。 – Phoca
非常感謝,我會研究它,然後報告回來 –