I am trying to put button between two list view which are vertically aligned.Can someone please help me out with the problem.I am very new to android ,I don't have any idea how to do that.
I want to put two small button in the space available between two columns.Please find the below xml code :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.edkul.vimal.edkul.Library"
android:id="#+id/linearLayout1"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/library"
android:textSize="25sp"
android:id="#+id/textView27"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="35dp"
android:layout_below="#+id/textView27">
<ListView
android:id="#+id/list_item1"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_marginRight="55dp"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:background="#88FF0000">
</ListView>
<ListView
android:id="#+id/list_item3"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:background="#88FF0000">
</ListView>
</LinearLayout>
<Button
android:layout_width="match_parent"
android:layout_below="#+id/linearLayout2"
android:layout_height="match_parent"
android:text="Button1"/>
</RelativeLayout>
Try with this.
Replace this full code in your XML.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.edkul.vimal.edkul.Library">
<TextView
android:id="#+id/textView27"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="Library"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="25sp" />
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/textView27"
android:layout_marginTop="35dp"
android:orientation="horizontal"
android:weightSum="2">
<ListView
android:id="#+id/list_item1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_weight="1"
android:background="#88FF0000"></ListView>
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="vertical"
android:weightSum="2">
<Button
android:id="#+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button1" />
<Button
android:id="#+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button1" />
</LinearLayout>
<ListView
android:id="#+id/list_item3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_weight="1"
android:background="#88FF0000"></ListView>
</LinearLayout>
</RelativeLayout>
It will show you button exactly between your listviews.
Surely it will help you.
Make the layout orientation as horizontal .use your first list views and button as 3views in your layout .
Make height as match parent for listviews but wrap content for button .
Check if it works
Related
I have a horizontal linear layout, with 3 buttons, on the display. I want this layout to be displayed in the bottom of the display.
Here is the code I wrote:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context="flowepower.tetris.Game"
android:background="#drawable/Main_screen">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:orientation="horizontal"
</LinearLayout> </RelativeLayout>
I haven't put the buttons code, they are simple ones.
With this code, it is still displayed on the top. Can you suggest me other posibilities? Thank you!
You can try this:Layout
<?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:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button2" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button3" />
</LinearLayout>
</RelativeLayout>
Hope this is what you want...
Hope this code works for you.
<?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:gravity="bottom"
android:orientation="horizontal" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
</LinearLayout>
As you are using RelativeLayout write android:alignParentBottom="true" in your LinearLayout tag.
<RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:alignParentBottom="true">
</LinearLayout>
</RelativeLayout>
I want to have two buttons that is fixed on the bottom screen like a footer and other views won't make pass on it or overlap on the two buttons. It will just stay still on the bottom always. Sorry for my English. Please help me. Btw I cannot post images so it requires 10 reputation that's why I used online image viewing. Sorry for that.
Here is the screenshot of my work which is wrong
http://postimg.org/image/pzry53ey9/
As you can see the multiline edit text overlaps on the two buttons as well as the scrollview. How to fix that?
Here is my code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="#drawable/ic_launcher" />
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true" />
<EditText
android:id="#+id/editText3"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</ScrollView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="bottom" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="#+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Save" />
<Button
android:id="#+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Cancel" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
Try this way,hope this will help you to solve your problem.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="#drawable/ic_launcher" />
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true" />
<EditText
android:id="#+id/editText3"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Save" />
<Button
android:id="#+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Cancel" />
</LinearLayout>
</LinearLayout>
your layout is quite complex for a simple view but i have modified it to achieve what you want
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/relativeLayout1"
android:layout_marginBottom="5dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="#drawable/ic_launcher" />
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true" />
<EditText
android:id="#+id/editText3"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</ScrollView>
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="bottom" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="#+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Save" />
<Button
android:id="#+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Cancel" />
</LinearLayout>
</RelativeLayout>
You don't need the RelativeLayout containing the LinearLayout that holds your buttons...get rid of the RelativeLayout and specify the LinearLayout like so:
<LinearLayout
android:id="#+id/buttons_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="true" >
Next, since your parent Layout is RelativeLayout, you'll need to specify the positioning of your ScrollView containing the EditText:
<ScrollView
android:layout_above="#+id/buttons_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
Also, if you want the buttons to stay at the very bottom of your view then remove this line from the parent Layout:
android:paddingBottom="#dimen/activity_vertical_margin"
Hope this helps!
Your root layout file is relative layout. It allows overlapping of UI elements(z-index placement). So you need to provide the boundary for a view to extend. Assign a android:id= "#+id\relativeLayout" to your relative layout(bottom not root). Then in your scrollview put
android:layout_above="#+id\relativeLayout". Follow similar approach for other views.
I am using a webview to load html data.
I want to place two buttons on the bottom for some functionality.
I have put teh webview and the bottom layout in a frame layout.
Web view shows html data only when i give it some specific height e.g 500dp.
Also the bottom layout also scrolls along with webview.
Please help how i can do 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"
android:padding="10dp" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/newsHeading"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:padding="5dp"
android:text="Heading"
android:textColor="#000000"
android:textSize="18sp" />
<WebView
android:id="#+id/webviewNews"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="30dp" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#color/black"
android:padding="10dp" >
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/back1"
android:padding="20dp" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="#drawable/share11"
android:padding="20dp" />
</RelativeLayout>
</FrameLayout>
</LinearLayout>
I had the same problem and I have fixed it by changing the LinearLayout by a RelativeLayout and setting all the "parent aligments" to the WebView, but this fill the screen.
For your layout, try align your button's LinearLayout to the parent's bottom, and replace the alignParentBottom of the WebView by a layout_above anchored to it. I have tested it and works fine.
Here is the code, try it:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="#+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_above="#+id/linlyt_buttons"/>
<LinearLayout
android:id="#+id/linlyt_buttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_alignParentBottom="true">
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button1"/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button2"/>
</LinearLayout>
<RelativeLayout
android:id="#+id/rellyt_imagebuttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
android:background="#color/black"
android:padding="10dp">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:drawable/ic_menu_close_clear_cancel"
android:padding="20dp"
android:contentDescription="Back/Cancel"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="#android:drawable/ic_menu_share"
android:padding="20dp"
android:contentDescription="Share"/>
</RelativeLayout>
</RelativeLayout>
Try this way,hope this will help you to solve your problem.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<WebView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp">
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button1"/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button2"/>
</LinearLayout>
</LinearLayout>
I have this layout : first, is a spinner, after that is a listview, after that is a linearlayout include EditText and Button, and at the bottom of the screen is a Button.
Here is my first layout file:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
android:orientation="vertical">
<Spinner
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:textColor="#0e0e0e"
android:layout_above="#+id/list_view"
android:id="#+id/spinner"/>
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/list_view"
android:layout_alignParentLeft="true"
android:layout_above="#+id/linear_layout" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="#+id/linear_layout"
android:layout_above="#+id/search_btn"
android:weightSum="3"
android:layout_alignParentLeft="true">
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="#+id/insert_chord_edit_text"
android:layout_weight="2"
android:text=""/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="#+id/add_chord_button"
android:layout_weight="1"
android:text="Add"/>
</LinearLayout>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/search_btn"
android:text="Search"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="32dp" />
</RelativeLayout>
Everything works fine, except that I cannot see Spinner. (and I have tested on real device). after that, I change layout above. Instead of say : spinner is above listview and listview is above of linearlayout. I change to : listview is below of spinner and listview is above of linearlayout. I have change as below layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
android:orientation="vertical">
<Spinner
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:textColor="#0e0e0e"
android:id="#+id/spinner"/>
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/list_view"
android:layout_alignParentLeft="true"
android:layout_below="#+id/spinner" // ADD THIS LINE
android:layout_above="#+id/linear_layout" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="#+id/linear_layout"
android:layout_above="#+id/search_btn"
android:weightSum="3"
android:layout_alignParentLeft="true">
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="#+id/insert_chord_edit_text"
android:layout_weight="2"
android:text=""/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="#+id/add_chord_button"
android:layout_weight="1"
android:text="Add"/>
</LinearLayout>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/search_btn"
android:text="Search"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="32dp" />
</RelativeLayout>
And it works as I want, but I cannot explain why. Please tell me.
Thanks :)
In first case, your listview was mentioned as height fill parent and it has layout_above attribute but no layout_below attribute. So the listview occupied all height above the linear_layout element. Thats why you cant see the spinner.as the spinner visibility is overridden by listview.
// try this
<?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:padding="5dp"
android:orientation="vertical" >
<Spinner
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="#0e0e0e"
android:id="#+id/spinner"/>
<ListView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:id="#+id/list_view"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="5dp"
android:id="#+id/linear_layout">
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="#+id/insert_chord_edit_text"
android:layout_weight="2"
android:text=""/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="#+id/add_chord_button"
android:layout_weight="1"
android:text="Add"/>
</LinearLayout>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/search_btn"
android:text="Search"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"/>
</LinearLayout>
set layout_weight="1" for your Spinner may solve your problem.
I want an activity with below layout:
top button
middle(scroll view)
bottom button
I want the bottom button to attach to the bottom of the activity view, and the middle part occupies the rest of the space.
How I can write the layout xml file?
Below doesn't work:
<?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:focusable="true"
android:focusableInTouchMode="true" android:layout_width="0px"
android:layout_height="0px" />
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent" android:weightSum="1" android:layout_height="wrap_content">
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:weightSum="1">
<EditText android:id="#+id/edit_search"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:lines="1" android:hint="发微博内容" android:layout_weight="0.9" />
<Button android:layout_height="wrap_content" android:text="Search"
android:layout_width="wrap_content" android:id="#+id/search_btn"
android:layout_weight="0.1"></Button>
</LinearLayout>
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="#+id/TextView01"
android:paddingTop="5dip" />
<ListView android:layout_width="fill_parent"
android:id="#+id/lv01" android:layout_height="390dp">
</ListView>
<Button android:id="#+id/create_new_btn"
android:layout_height="wrap_content" android:text="我要评论" android:layout_gravity="bottom"
android:layout_width="fill_parent"></Button>
</LinearLayout>
</LinearLayout>
For that case, just take a RelativeLayout, its better for this case and you don't need to take any sub-layout.
Just try this once and post your XML layout here for the further improvement.
From your xml layout code, i can assume, you just want to have:
EditText+Button=>Top,
TextView+ListView=>Middle,
Create New button=>Bottom,
is this the case?
Keep it simple, go with LinearLayout, and play with the weights:
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0">
</Button>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<!-- Stuff in scroll view -->
</ScrollView>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0">
</Button>
</LinearLayout>
#ParashMayani is right..
Here is the implementation :
<LinearLayout android:focusable="true"
android:focusableInTouchMode="true" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="#+id/relLayout" android:orientation="horizontal" >
<EditText android:id="#+id/edit_search"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:lines="1" android:hint="Hello" android:layout_weight="0.7"/>
<Button android:layout_height="wrap_content" android:text="Search"
android:layout_weight="0.3" android:layout_width="wrap_content" android:id="#+id/search_btn" />
</LinearLayout>
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="#+id/TextView01"
android:paddingTop="5dip" android:layout_below="#id/relLayout"/>
<Button android:id="#+id/create_new_btn"
android:layout_height="wrap_content" android:text="我要评论" android:layout_gravity="bottom"
android:layout_width="fill_parent" android:layout_alignParentBottom="true"/>
<ListView android:layout_width="fill_parent"
android:id="#+id/lv01" android:layout_height="0dp" android:layout_above="#id/create_new_btn" android:layout_below="#id/TextView01" />
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button android:id="#+id/button1" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="Button" android:layout_alignParentTop="true" android:layout_alignParentLeft="true"></Button>
<Button android:id="#+id/button2" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="Button" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true"></Button>
<ScrollView android:id="#+id/scrollView1" android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_below="#+id/button1" android:layout_above="#+id/button2">
<LinearLayout android:id="#+id/linearLayout1" android:layout_width="match_parent" android:layout_height="match_parent"></LinearLayout>
</ScrollView>
</RelativeLayout>
I think something like that would work. The important part in that layout is the android:layout_below and android:layout_above. You can replace the ScrollView with other layouts such as ListView and it will remain below the first button and above the second regardless of how big it gets. Likewise, the buttons have the attributes android:layout_alignParentTop="true" and android:layout_alignParentBottom="true" which will keep them to the top and the bottom of the RelativeView respectively.