[英]How to implement android XML for the attached image (layout)?
我需要實現我的android布局,如下圖所示:
A- 應以以下方式固定組件
B- 應占據75%的屏幕空間,並具有垂直滾動條
我的問題是,我的Android XML看起來如何? 伙計們在此先感謝。
我的XML如下:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android1="http://schemas.android.com/apk/res/android"
android:id="@+id/tvDate"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<RelativeLayout
android1:layout_width="match_parent"
android1:layout_height="match_parent" >
<NumberPicker
android1:id="@+id/numberPicker2"
android1:layout_width="wrap_content"
android1:layout_height="wrap_content"
android1:layout_alignTop="@+id/numberPicker1"
android1:layout_toRightOf="@+id/numberPicker1" />
<NumberPicker
android1:id="@+id/numberPicker3"
android1:layout_width="wrap_content"
android1:layout_height="wrap_content"
android1:layout_alignTop="@+id/numberPicker2"
android1:layout_toRightOf="@+id/numberPicker2" />
<NumberPicker
android1:id="@+id/numberPicker4"
android1:layout_width="wrap_content"
android1:layout_height="wrap_content"
android1:layout_alignBottom="@+id/numberPicker3"
android1:layout_toRightOf="@+id/numberPicker3" />
<NumberPicker
android1:id="@+id/numberPicker5"
android1:layout_width="wrap_content"
android1:layout_height="wrap_content"
android1:layout_alignTop="@+id/numberPicker4"
android1:layout_toRightOf="@+id/numberPicker4" />
<NumberPicker
android1:id="@+id/numberPicker6"
android1:layout_width="wrap_content"
android1:layout_height="wrap_content"
android1:layout_alignBottom="@+id/numberPicker5"
android1:layout_toRightOf="@+id/numberPicker5" />
<NumberPicker
android1:id="@+id/numberPicker7"
android1:layout_width="wrap_content"
android1:layout_height="wrap_content"
android1:layout_alignBottom="@+id/numberPicker6"
android1:layout_toRightOf="@+id/numberPicker6" />
<NumberPicker
android1:id="@+id/numberPicker8"
android1:layout_width="wrap_content"
android1:layout_height="wrap_content"
android1:layout_alignTop="@+id/numberPicker7"
android1:layout_toRightOf="@+id/numberPicker7" />
<TextView
android1:id="@+id/textView1"
android1:layout_width="wrap_content"
android1:layout_height="wrap_content"
android1:layout_alignLeft="@+id/numberPicker1"
android1:layout_alignParentTop="true"
android1:layout_marginTop="22dp"
android1:text="Start Mileage"
android1:textAppearance="?android:attr/textAppearanceMedium" />
<ImageView
android1:id="@+id/imageView1"
android1:layout_width="wrap_content"
android1:layout_height="wrap_content"
android1:layout_alignParentTop="true"
android1:layout_marginRight="25dp"
android1:layout_toLeftOf="@+id/textView1"
android1:src="@drawable/line" />
<Button
android1:id="@+id/button1"
android1:layout_width="wrap_content"
android1:layout_height="wrap_content"
android1:layout_alignParentLeft="true"
android1:layout_alignTop="@+id/textView1"
android1:layout_toLeftOf="@+id/imageView1"
android1:text="Request Bundle" />
<EditText
android1:id="@+id/editText2"
android1:layout_width="wrap_content"
android1:layout_height="wrap_content"
android1:layout_alignBaseline="@+id/textView3"
android1:layout_alignBottom="@+id/textView3"
android1:layout_toLeftOf="@+id/imageView1"
android1:layout_toRightOf="@+id/textView5"
android1:ems="10" />
<TextView
android1:id="@+id/textView4"
android1:layout_width="wrap_content"
android1:layout_height="wrap_content"
android1:layout_alignLeft="@+id/textView3"
android1:layout_below="@+id/editText2"
android1:layout_marginTop="29dp"
android1:text="Driver Name"
android1:textAppearance="?android:attr/textAppearanceSmall" />
<EditText
android1:id="@+id/editText3"
android1:layout_width="wrap_content"
android1:layout_height="wrap_content"
android1:layout_alignBaseline="@+id/textView4"
android1:layout_alignBottom="@+id/textView4"
android1:layout_alignRight="@+id/editText2"
android1:layout_toRightOf="@+id/textView5"
android1:ems="10" />
<TextView
android1:id="@+id/textView5"
android1:layout_width="wrap_content"
android1:layout_height="wrap_content"
android1:layout_alignLeft="@+id/textView4"
android1:layout_below="@+id/editText3"
android1:layout_marginTop="31dp"
android1:text="Number of passengers"
android1:textAppearance="?android:attr/textAppearanceSmall" />
<EditText
android1:id="@+id/editText4"
android1:layout_width="wrap_content"
android1:layout_height="wrap_content"
android1:layout_alignBaseline="@+id/textView5"
android1:layout_alignBottom="@+id/textView5"
android1:layout_toLeftOf="@+id/imageView1"
android1:layout_toRightOf="@+id/textView5"
android1:ems="10" />
<TextView
android1:id="@+id/textView3"
android1:layout_width="wrap_content"
android1:layout_height="wrap_content"
android1:layout_alignParentLeft="true"
android1:layout_below="@+id/button1"
android1:layout_marginLeft="26dp"
android1:layout_marginTop="27dp"
android1:text="Vehicle Number"
android1:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android1:id="@+id/textView2"
android1:layout_width="wrap_content"
android1:layout_height="wrap_content"
android1:layout_alignLeft="@+id/textView5"
android1:layout_centerVertical="true"
android1:text="Date"
android1:textAppearance="?android:attr/textAppearanceSmall" />
<EditText
android1:id="@+id/editText1"
android1:layout_width="wrap_content"
android1:layout_height="wrap_content"
android1:layout_alignRight="@+id/editText4"
android1:layout_centerVertical="true"
android1:layout_toRightOf="@+id/textView5"
android1:ems="10" >
<requestFocus />
</EditText>
<NumberPicker
android1:id="@+id/numberPicker1"
android1:layout_width="wrap_content"
android1:layout_height="wrap_content"
android1:layout_below="@+id/textView1"
android1:layout_marginLeft="242dp"
android1:layout_toRightOf="@+id/textView5" />
</RelativeLayout>
</ScrollView>
現在,我認為您應該再次閱讀自己的要求。 您已經提到了A和B,因此顯然您必須使用兩個容器(假設您確定Fragments不是更好的選擇)。 為什么只使用一個?
並且只用滾動視圖包裝第二個容器。 如果將ScrollView放在最外層, 一切都會滾動!
使用外部LinearView並給內部容器一些權重(左邊一個android:layout_weight="1"
,右邊一個android:layout_weight="3"
)。 配重會使用任何剩余空間,並根據其在總重量中所占的百分比進行分配。 因此,在這種情況下,您有25%和75%。
您應該真正了解這些布局。 請參閱有關此文檔的Android文檔或查看Styling Android博客。 如果您不了解Eclipse布局編輯器生成的內容,則將無法獲得預期的結果。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.