1
我想設計是這樣的:左浮動的TextView和TableLayout
[TableLayout 1 Title] TextView1
[TableLayout 1]
[TableLayout 2 Title] TextView2
[TableLayout 2]
就像在CSS,我們只需使用:浮子:用設置t離開他在100%的寬度,一切都很好。
,所以這是我的佈局XML代碼:
<RelativeLayout
android:layout_width="match_parent"
android:background="#e9e9e9"
android:layout_height="match_parent" >
<TextView
android:id="@+id/TextView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="Visitors per Category"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#324A61"
android:layout_marginLeft="7dp"
android:layout_marginTop="25dp"
android:textStyle="bold" />
<TableLayout
android:id="@+id/TableLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginTop="50dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="7dp"
android:layout_marginRight="7dp"
android:stretchColumns="2"
android:background="@drawable/shape" >
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="15dp" >
// Some EditText etc...
</TableRow>
// Separator border
<View
android:id="@+id/firstDivider"
android:layout_height="2dp"
android:layout_width="fill_parent"
android:background="#666" />
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="15dp" >
// Some textviews etc...
</TableRow>
</TableLayout>
<TextView
android:id="@+id/EditText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginBottom="60dp"
android:text="Scans per Gate"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#324A61"
android:textStyle="bold" />
<TableLayout
android:id="@+id/TableLayout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginTop="205dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="7dp"
android:layout_marginRight="7dp"
android:stretchColumns="2"
android:background="@drawable/shape" >
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="15dp" >
// some textviews etc...
</TableRow>
<View
android:id="@+id/firstDivider"
android:layout_width="fill_parent"
android:layout_height="2dp"
android:background="#666" />
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="15dp" >
// Some textViews
</TableRow>
</TableLayout>
</RelativeLayout>
一切看起來正常,我的代碼,但圖形我有類似:
TextView2
TextView1
TableLayout2
TableLayout1
你對此有什麼想法嗎?
謝謝。
哇!它完美的作品!這絕對是一個很好的答案! 但請您可以告訴我爲什麼使用線性佈局?謝謝。 – Copernic
如果它工作,請[accept_the_answer](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work)。LinearLayout用於想要線性對齊您的子視圖通過給定方向爲水平或垂直。有關更多信息,請參閱[佈局](http://developer.android.com/guide/topics/ui/declaring-layout.html) – Manishika
謝謝您的回答。 – Copernic