Reputation: 593
I need to implement my android layout as the image below:
A - Should hold the components in the following manner
B - Should take up 75% of the screen space and should have a vertical scroll bar
My question is, how would my Android XML look like? Guys thanks in advance.
My XML is as follows:
<?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>
Upvotes: 0
Views: 258
Reputation: 2402
Now I think you should read your requirements once more yourself. You already mentioned A and B, so obviously you have to use two containers (assuming you are sure, that Fragments aren't a better choice). Why do you use only one?
And only wrap the second container with a scrollview. If you put the ScrollView at the outer most level everything scrolls!
Use an outer LinearView and give the inner containers some weights (the left one android:layout_weight="1"
and the right one android:layout_weight="3"
). Weights use any remaining space and distribute it according to their percentage of the toal weight. So in this case you have 25% and 75%.
You should really read about those layouts. See the Android documentation about it or have a look at the blog Styling Android. If you cannot understand what the Eclipse layout editor generates, you won't get desired results with it.
Upvotes: 1