Can i Convert this Linear Layout view into Relative Layout view with proper weight.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1.2"
android:weightSum="3" >
<Button
android:id="#+id/favButton2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1.2" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight=".6"
android:weightSum="2" >
<EditText
android:id="#+id/searchText"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight=".6" />
<Button
android:id="#+id/gotoButton"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1.4" />
</LinearLayout>
<Button
android:id="#+id/favButton4"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1.2" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1.2"
android:background="#drawable/appback" >
<TextView
android:id="#+id/category"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:textColor="#000" />
</LinearLayout>
<ScrollView
android:id="#+id/scrollBackground"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight=".4"
android:background="#drawable/appback" >
<TextView
android:id="#+id/favSms"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp" />
</ScrollView>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1.2"
android:weightSum="2" >
<Button
android:id="#+id/nextFavSms"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="Next" />
<Button
android:id="#+id/PreFavSms"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="Pre" />
</LinearLayout>
this is the o/p which i am getting from the above linear layout i want the same using relative layout that support all the devices.
I think in Relative Layout you can't use weight but you can achieve this design can you make your question clear. What your finding difficult in designing this layout? Relative layout would be better if you go for different screen size
Related
How can I adjust the width of my 2 Relative Layouts correctly, so that the one to the left takes 0.25 of screen space and the one to the right takes 0.75? Inside the second relative layout there's a table layout with 3 columns, each of them should take 1/3 of table's size.
Here's what I've tried with AXML
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="0.25">
<LinearLayout
android:id="#+id/buttonsLeft"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<Button
android:id="#+id/buttonBack"
android:text="#string/btnBack"
android:layout_width="#dimen/myBtnWidth"
android:layout_height="#dimen/myBtnHeight"
android:layout_marginTop="#dimen/myBtnMargin"
android:layout_marginLeft="#dimen/myBtnMargin" />
<Button
android:id="#+id/buttonStart"
android:text="#string/btnStart"
android:layout_width="#dimen/myBtnWidth"
android:layout_height="#dimen/myBtnHeight"
android:layout_marginTop="#dimen/myBtnMargin"
android:layout_marginLeft="#dimen/myBtnMargin" />
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="0.75">
<LinearLayout
android:id="#+id/tableRight"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/tableLayout1">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical">
<TextView
android:id="#+id/Text1"
android:padding="10sp"
android:textSize="#dimen/myTextSizeColHeader"
android:text="#string/bin"
android:layout_height="wrap_content"
android:layout_width="#dimen/myColWidthBin"
android:gravity="left" />
<TextView
android:id="#+id/Text2"
android:padding="10sp"
android:textSize="#dimen/myTextSizeColHeader"
android:text="#string/item_customer"
android:layout_height="wrap_content"
android:layout_width="#dimen/myColWidthItemCust"
android:gravity="center" />
<TextView
android:id="#+id/Text4"
android:padding="10sp"
android:textSize="#dimen/myTextSizeColHeader"
android:text="#string/nominal_actualQty"
android:layout_height="wrap_content"
android:layout_width="#dimen/myColWidthActNomQty"
android:gravity="right" />
</TableRow>
<ListView
android:id="#+id/whseActivHeadersList" />
</TableLayout>
</LinearLayout>
</RelativeLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="52.5dp"
android:id="#+id/notificationsNextorder"
android:textSize="14sp"
android:textStyle="bold" />
</LinearLayout>
Result:
Add weightSum to parent linear layout.
Check this answer
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="4">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3">
</RelativeLayout>
I'm new android. I have a little bit stack in designing layout for Android. In my scenario, I have two button with Linear Layout. Here my xml.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:background="#color/isp_home_color"
>
<Button
android:layout_width="0dp"
android:layout_height="70dp"
android:layout_weight="1"
android:text="#string/sync_text"
android:background="#color/sync_text_color"
android:id="#+id/btn_syncpin"
android:layout_gravity="left"
android:textStyle="bold"
/>
<Button
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="70dp"
android:text="#string/topup_text"
android:background="#color/topup_text_color"
android:id="#+id/btn_topup"
android:layout_gravity="right"
android:textStyle="bold"/>
<!--Table Layout will come here -->
</LinearLayout>
Here image for this.
When I add new TableLayout inside Linear Layout. I got this.
Here my xml for Table Layout.
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</TableLayout>
Actually, I don't want like this. I want two button as shown in first image. Then, next table layout will occur under this two button. Please help me how can I do this layout. Please pointing to me how to make this. Thanks with advanced.
Give orientation as vertical to the LinearLayout not the TableLayout.Put Two buttons in a LinearLayout with orizontal orientation and give orientation "vertical" for the parent LinearLayout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#456789"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:orientation="horizontal">
<Button
android:id="#+id/btn_syncpin"
android:layout_width="wrap_content"
android:layout_height="70dp"
android:layout_gravity="left"
android:layout_weight="1"
android:background="#123456"
android:text="tring/"
android:textStyle="bold" />
<Button
android:id="#+id/btn_topup"
android:layout_width="wrap_content"
android:layout_height="70dp"
android:layout_gravity="right"
android:layout_weight="1"
android:background="#978969"
android:text="topup_text"
android:textStyle="bold" />
</LinearLayout>
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF" >
</TableLayout>
</LinearLayout>
Check this out, I just checked it on my Machine and it works as desired, although the background preference and the display strings have been removed.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="#+id/btn_syncpin"
android:layout_width="0dp"
android:layout_height="70dp"
android:layout_gravity="left"
android:layout_weight="1"
android:textStyle="bold" />
<Button
android:id="#+id/btn_topup"
android:layout_width="0dp"
android:layout_height="70dp"
android:layout_gravity="right"
android:layout_weight="1"
android:textStyle="bold" />
</LinearLayout>
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_below="#+id/linearLayout2">
</TableLayout>
</RelativeLayout>
take Relative Layout as a parent layout.
Following is an example. it will display your buttons and table layout too
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/isp_home_color"
android:orientation="horizontal" >
<Button
android:id="#+id/btn_syncpin"
android:layout_width="0dp"
android:layout_height="70dp"
android:layout_gravity="left"
android:layout_weight="1"
android:background="#color/sync_text_color"
android:text="#string/sync_text"
android:textStyle="bold" />
<Button
android:id="#+id/btn_topup"
android:layout_width="0dp"
android:layout_height="70dp"
android:layout_gravity="right"
android:layout_weight="1"
android:background="#color/topup_text_color"
android:text="#string/topup_text"
android:textStyle="bold" />
</LinearLayout>
<TableLayout
android:id="#+id/table"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/linearLayout2" >
</TableLayout>
</RelativeLayout>
thanks
This answer tells only implementation of button_bar_layout for all android versions with buttons at the bottom/top of an activity which look like AlertDialog with OK/Cancel buttons.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="?android:attr/listDivider"
android:orientation="vertical"
android:showDividers="middle" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#null"
android:divider="?android:attr/listDivider"
android:dividerPadding="12dp"
android:orientation="horizontal"
android:showDividers="middle" >
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#android:drawable/list_selector_background"
android:paddingLeft="4dp"
android:paddingRight="4dp"
android:text="One" />
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#android:drawable/list_selector_background"
android:paddingLeft="4dp"
android:paddingRight="4dp"
android:text="Two" />
</LinearLayout>
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF" >
</TableLayout>
</LinearLayout>
Credits: Who else ? Johnkil
// try this way here i gave you alternative to achieve your requirement from give all of above
1. header.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#color/isp_home_color">
<Button
android:layout_width="0dp"
android:layout_height="70dp"
android:layout_weight="1"
android:text="#string/sync_text"
android:background="#color/sync_text_color"
android:id="#+id/btn_syncpin"
android:textStyle="bold"/>
<Button
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="70dp"
android:text="#string/topup_text"
android:background="#color/topup_text_color"
android:id="#+id/btn_topup"
android:textStyle="bold"/>
</LinearLayout>
2.main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp"
android:orientation="vertical">
<include
layout="#layout/header"/>
<TableLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="10dp"
android:layout_weight="1">
</TableLayout>
</LinearLayout>
I have a problem with relativelayout where its children could use layout_below and layout_weight to set its percentage height.
For example, we have a relative layout and inside of it we have three linear layouts with textviews. Now, I would like to set for three of them (linearlayouts) 25,50,25 % of height of total height of relative layout. How could I accomplish it?
I found a solution for weight_sum and and relativelayout (CLICK), but it doesn't use layout_below.
How can I fix this?
I tried to add additional linearlayout inside of all linearlayouts, but then I am unable use layout_below.
Here is concept picture idea:
Here is my code:
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/linlay_leftcol_notification_header" >
<LinearLayout
android:id="#+id/linlay_leftcol_clock_theday"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/tv_theday"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/theday"
android:textColor="#FFFFFF" />
</LinearLayout>
<LinearLayout
android:id="#+id/linlay_leftcol_clock_thetime"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/linlay_leftcol_clock_theday" >
<TextView
android:id="#+id/tv_thetime"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/thetime"
android:textColor="#FFFFFF" />
</LinearLayout>
<LinearLayout
android:id="#+id/linlay_leftcol_clock_thenumber_themonth_theyear"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/linlay_leftcol_clock_thetime" >
<TextView
android:id="#+id/tv_thenumberofday_themonth_theyear"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/thenumberofday_themonth_theyear"
android:textColor="#FFFFFF" />
</LinearLayout>
</RelativeLayout>
Try this...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="#ff00ff"
android:orientation="vertical">
<RelativeLayout
android:layout_weight="1"
android:background="#ffff00"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/textView0"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="Hello 1"
android:textColor="#000000"
android:textSize="15dp" />
</RelativeLayout>
<RelativeLayout
android:layout_weight="2"
android:background="#00ffff"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="Hello 2"
android:textColor="#000000"
android:textSize="15dp" />
</RelativeLayout>
<RelativeLayout
android:layout_weight="1"
android:background="#ffff00"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/textView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="Hello 3"
android:textColor="#000000"
android:textSize="15dp" />
</RelativeLayout>
</LinearLayout>
Check out this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight=".15"
android:background="#android:color/background_dark"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/rel_1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#A52A2A" >
<TextView
android:id="#+id/tv_theday"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="1st layout"
android:textColor="#FFFFFF" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rel_2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#8B008B" >
<TextView
android:id="#+id/tv_theday"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="2ndlayout"
android:textColor="#FFFFFF" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rel_3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#00008B" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="3rd layout"
android:textColor="#FFFFFF" />
</RelativeLayout>
</LinearLayout>
<RelativeLayout
android:id="#+id/rel_side"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight=".75"
android:background="#ff0000" >
<TextView
android:id="#+id/tv_theday"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="side layout"
android:textColor="#FFFFFF" />
</RelativeLayout>
</LinearLayout>
You may use either weight or relative layout properties. You can make that 25,50,25 like this...you align the parent left first textview, align parent right, other textview, and the remaining textview's you align to the left of the first one and to the right of the last one.
Use Table Layout and inside that, you put your textviews. There is an attribute, "stretch column", for table layout. There you can mention the size as " 0,2,1" like that...
I've got a relativelayout with three linearlayouts as children. The last one has a fixed height and has android:layout_alignParentBottom set to "true". While the middle one is properly positioned below the first one, it goes as far as the bottom of the screen, so that its lower part is overlapped by the third one.
What's wrong?
Thanks
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="#+id/category"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:orientation="horizontal" >
<ImageView
android:id="#+id/back_btn"
android:layout_width="29dp"
android:layout_height="34dp"
android:layout_gravity="center_vertical"
android:src="#drawable/red_arrow_left" />
<TextView
android:id="#+id/cat_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/category"
android:layout_marginTop="10dp"
android:orientation="horizontal" >
<ListView
android:id="#+id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/white"
android:cacheColorHint="#android:color/white" />
<TextView
android:id="#+id/android:empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/white"
android:cacheColorHint="#android:color/white"
android:padding="10dp"
android:text="#string/no_item" />
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/nav_bar"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >
//stuff
</LinearLayout>
</RelativeLayout>
You could try using layout weights to control the relative sizes of the child layouts. There is an article on my blog which gives some information on the use of layout weights.
As an example, try this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/category"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:orientation="horizontal" >
<ImageView
android:id="#+id/back_btn"
android:layout_width="29dp"
android:layout_height="34dp"
android:layout_gravity="center_vertical" />
<TextView
android:id="#+id/cat_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/category"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:orientation="horizontal" >
<ListView
android:id="#+id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/white"
android:cacheColorHint="#android:color/white" />
<TextView
android:id="#+id/android:empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/white"
android:cacheColorHint="#android:color/white"
android:padding="10dp"
android:text="no_item" />
</LinearLayout>
<LinearLayout
android:id="#+id/nav_bar"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:orientation="horizontal" >
//stuff
</LinearLayout>
</LinearLayout>
The RelativeLayout has been replaced by a LinearLayout, all of the relative positioning tags have been removed, and a layout_weight attribute has been added to the centre LinearLayout which will cause it to stretch to fill the available space.
Nooo... the solution is much simpler! You forgot to say that you wanted the second linear layout to be above the third one :) Yes, the second linear layout must have BOTH android:layout_below="#+id/category" and android:layout_above="#+id/nav_bar". I tested it and it works.
But of course, you can use weights to achieve the same results, it is just going to be harder...
Here is your XML with the change I mentioned (tested it in eclipse):
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="#+id/category"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:orientation="horizontal" >
<ImageView
android:id="#+id/back_btn"
android:layout_width="29dp"
android:layout_height="34dp"
android:layout_gravity="center_vertical"
android:src="#drawable/red_arrow_left" />
<TextView
android:id="#+id/cat_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/nav_bar"
android:layout_below="#+id/category"
android:layout_marginTop="10dp"
android:orientation="horizontal" >
<ListView
android:id="#+id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/white"
android:cacheColorHint="#android:color/white" />
<TextView
android:id="#+id/android:empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/white"
android:cacheColorHint="#android:color/white"
android:padding="10dp"
android:text="#string/no_item" />
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/nav_bar"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >
//stuff
</LinearLayout>
</RelativeLayout>
You should add an id to your second LinearLayout
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/category"
android:layout_marginTop="10dp"
android:id="#+id/YOUR_ID">
and in the third layout add android:layout_below="#id/YOUR_ID"
<LinearLayout
android:id="#+id/nav_bar"
android:layout_below="#id/YOUR_ID"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_alignParentBottom="true">
I want create a layout, with a horizontal LinearLayout(s) on top and bottom, a ListView fill in middle.
How can I define the main.xml.
I tried to create a layout with horizontal LinearLayout on top, TextView on bottom, a ListView fill in middle; is ok. But after I modified the bottom TextView to LinearLayout, the bottom LinearLayout disappear.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<TextView
android:textSize="12px"
android:text="something here"
android:layout_width="50px"
android:layout_height="wrap_content"
/>
<TextView
android:textSize="12px"
android:text="something here"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="bottom"
>
<ListView
android:id="#+id/listbody"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<LinearLayout
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
>
<TextView
android:layout_height="wrap_content"
android:layout_width="0dip"
android:layout_weight="1"
android:textSize="12px"
android:text="50%"
/>
<TextView
android:layout_height="wrap_content"
android:layout_width="0dip"
android:layout_weight="1"
android:textSize="12px"
android:text="50%"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Anybody can tell advise?
Please help.
Try containing the whole set in a RelativeLayout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="#+id/top_linear_layout_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" >
</LinearLayout>
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/bottom_linear_layout_id"
android:layout_below="#id/top_linear_layout_id" />
<LinearLayout
android:id="#+id/bottom_linear_layout_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
</LinearLayout>
</RelativeLayout>
Edited with sizing stuff.
Here's what you're looking for. Estel's on the right track with the RelativeLayout (although it can be done with a LinearLayout, I think the RelativeLayout approach is cleaner, though) but the layout is out of order Nevermind, check Estel's comment which proved me wrong. :) You should first define your header, align it to the top; next, define your footer, and align it to the bottom; finally, declare your ListView, give it a height of fill_parent, and set it to layout above the footer and below the header:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:id="#+id/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:alignParentTop="true"
>
</LinearLayout>
<LinearLayout
android:id="#+id/footer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:alignParentBottom="true"
>
</LinearLayout>
<ListView
android:id="#+id/listview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#id/footer"
android:layout_below="#id/header"
/>
</RelativeLayout>
The problem would be that you are defining both of them relative to the size of the content they contain, but if the combined content of both is bigger than the screen then one of them will have to overlap the other one, you would be better to define the layout_height using an absolute measurement in a linear layout
Thanks all for your advice and direction of RelativeLayout. I can fix it now.
I have to define the footer LinearLayout before the ListView, and define ListView as android:layout_alignParentTop="true" and android:layout_above="#id/footer"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<TextView
android:textSize="12px"
android:text="something here"
android:layout_width="50px"
android:layout_height="wrap_content"
/>
<TextView
android:textSize="12px"
android:text="something here"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
<RelativeLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:id="#+id/footer"
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_alignParentBottom="true"
>
<TextView
android:layout_height="wrap_content"
android:layout_width="0dip"
android:layout_weight="1"
android:textSize="12px"
android:text="50%"
/>
<TextView
android:layout_height="wrap_content"
android:layout_width="0dip"
android:layout_weight="1"
android:textSize="12px"
android:text="50%"
/>
</LinearLayout>
<ListView
android:id="#+id/tablebody"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_above="#id/footer"
/>
</RelativeLayout>
</LinearLayout>
This will definitely solve your problem:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:textSize="12sp"
android:text="something here"
android:layout_width="50dp"
android:layout_height="wrap_content"/>
<TextView
android:textSize="12sp"
android:text="something here"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</HorizontalScrollView>
<ListView
android:id="#+id/listbody"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="fill_parent">
<TextView
android:layout_height="wrap_content"
android:layout_width="0dip"
android:layout_weight="1"
android:textSize="12sp"
android:text="50%"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="0dip"
android:layout_weight="1"
android:textSize="12sp"
android:text="50%"/>
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>