I wanted to know how to center a View between two other views (or between a view and the parent edge) using RelativeLayout.
For example, if I have the following...
How do I vertically center the Button between the ImageView and the bottom of the screen using RelativeLayout?
I'm looking for a solution where...
the Button is not stretched in any way
there are no nested layouts
And I'm trying to do this in the XML layout (not programmatically).
You can use following:
<RelativeLayout
android:layout_below="#id/theImageView"
android:align_parentBottom="true"
android:layout_width="match_parent"
android:layout_height="200dp" >
<Button
android:id="#+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:onClick="onClickButton"
android:textSize="20sp"
android:text="Go"/>
</RelativeLayout>
There's unfortunately no easy way to do this. You can either nest layouts, or do it at runtime. The simplest way is to nest layouts:
<LinearLayout
android:width="match_parent"
android:height="match_parent"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/my_top_image"/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="#string/my_button_label"/>
</RelativeLayout>
</LinearLayout>
This puts the image at the top. Below that, the layout_height=0 and layout_weight=1 attributes on the RelativeLayout cause it to take up all the remaining space. You can then center the button in the RelativeLayout. You can play with padding on the button to get it to the size you want.
Use below XMl code for that, it will solve your problem.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="#+id/mLlayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:id="#+id/mImgView1"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="#drawable/ic_launcher" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="2" >
<Button
android:id="#+id/Btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Dipak" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
use this android:layout_centerInParent="true" in XML file..
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1.0" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="0.8"
android:background="#00ff00" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="0.2" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Button" />
</RelativeLayout>
</LinearLayout>
#Gus you can create center view between two other view... this is not exact you must try with
this way....
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="#00ccFF"
android:orientation="horizontal" >
</LinearLayout>
<LinearLayout
android:layout_width="59dp"
android:layout_height="59dp"
android:layout_alignRight="#+id/linearLayout1"
android:layout_alignTop="#+id/linearLayout1"
android:layout_marginRight="-21dp"
android:layout_marginTop="-21dp"
android:background="#FFccFF"
android:orientation="vertical" >
</LinearLayout>
</RelativeLayout>
I think what you just need is to allign the imageview as you would normally done and align the button using layout_below , no need for hardcoding nor using nested views use android:gravity="center" on the button you're done
<RelativeLayout
android:layout_below="#id/theImageView"
android:align_parentBottom="true"
android:layout_width="match_parent"
android:layout_height="200dp" >
<ImageView
android:id="#+id/imgview"
android:layout_width="match_parentmat"
android:layout_height="wrap_content" />
<Button
android:id="#+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/imgview"
android:gravity="center"
android:onClick="onClickButton"
android:textSize="20sp"
android:text="Go"/>
</RelativeLayout>
<?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" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:src="#drawable/wood" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/imageView1"
android:layout_below="#+id/imageView1"
android:layout_marginLeft="101dp"
android:layout_marginTop="53dp"
android:text="Image Button" />
</RelativeLayout>
Related
In my layout i want to display two imagebuttons in the center and a my amountmeter below it on the bottom, all centered vertically, i have tried many ways but cant seem to find that perfect layout. all the component align vertically and center but it makes my amountmeter small and not full width of the screen.
How it should be
how it is now
updated code
current layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical" >
<ImageButton
android:id="#+id/purchase"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#drawable/round_button"
android:src="#drawable/ic_cart" />
<ImageButton
android:id="#+id/sell"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#drawable/round_button"
android:src="#drawable/ic_sell" />
<com.example.mobile.view.AmountMeterView
android:id="#+id/mobileAmount"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center|bottom"
android:padding="4dp" />
COPY PASTE BELOW CODE
<?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"
android:orientation="horizontal" >
<ImageButton
android:id="#+id/purchase"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:src="#drawable/ic_launcher" />
<ImageButton
android:id="#+id/sell"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/purchase"
android:layout_centerHorizontal="true"
android:src="#drawable/ic_launcher" />
<com.example.mobile.view.AmountMeterView
android:id="#+id/mobileAmount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/sell"
android:padding="4dp"
android:src="#drawable/ic_launcher" />
</RelativeLayout>
AFTER THAT
android:background="#drawable/round_button"
android:src="#drawable/ic_sell"
android:background="#drawable/round_button"
android:src="#drawable/ic_cart"
PUT THIS LINE TO YOUR TWO IMAGE BUTTONS SURELY IT WILL WORK FOR YOU
One Linear layout is enough for this. Do not put your AmountMeterView into it's own LinearLayout.
Just make one Linear layout (vertical), and put all three elements in there. Gravity center_horizontal for all elements.
Try in this way hope this will help you
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<ImageButton
android:id="#+id/purchase"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#drawable/round_button"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<ImageButton
android:id="#+id/sell"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#drawable/round_button"
android:src="#drawable/ic_launcher" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
android:orientation="vertical" >
<com.example.mobile.view.AmountMeterView
android:id="#+id/mobileAmount"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="4dp" />
</LinearLayout>
</LinearLayout>
I am really getting frustrated with the layout as shown below:
I would like to have listview and below that I need to have two buttons side by side as shown above(LIstview should be scrollable and buttons should be as bottom bar ie..ontop tof the listview ). I have tried using android:layout_above and android:layout_below but nothing worked.Can anyone gimme an idea how to achieve this layout ?
This is what my layout code as of now actually I have this code where I am able to achieve this but I'm unable to click the buttons here.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/secondLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="15dp" >
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:id="#+id/firstLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#id/secondLayout"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#00ffffff"
android:gravity="bottom"
android:orientation="horizontal"
android:padding="15dp" >
<Button
android:id="#+id/btnPrevious"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_marginLeft="10dp"
android:layout_weight="1"
android:background="#drawable/redbutton"
android:onClick=""
android:text="Previous"
android:textColor="#ffffff" />
<Button
android:id="#+id/btnNext"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_marginLeft="10dp"
android:layout_weight="1"
android:background="#drawable/redbutton"
android:text="Next"
android:textColor="#ffffff" />
</LinearLayout>
Step #1: Get rid of the useless LinearLayout wrapping your ListView, moving the android:padding attribute into the ListView.
Step #2: Add android:layout_alignParentTop="true" and android:layout_above="#+id/firstLayout to the ListView.
Step #3: Get rid of android:layout_above="#id/secondLayout" from the remaining LinearLayout, as you definitely do not want that above the ListView.
Step #4: Switch from dp to sp for your Button dimensions, to take into account font scaling.
Step #5: Either change the width of the LinearLayout to wrap_content or remove the android:layout_centerHorizontal="true", as you cannot center something that fills all available space.
Off the cuff, the rest should be OK, or at least be a lot closer to what you want.
how about adding the buttons to your actionbar?
Otherwise wrap the ListView inside an ScrollView and make your RelativeLayout to LinearLayout
this is working. What problem are you facing exactly?
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/secondLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="15dp" >
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:id="#+id/firstLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#id/secondLayout"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#00ffff"
android:gravity="bottom"
android:orientation="horizontal"
android:padding="15dp" >
<Button
android:id="#+id/btnPrevious"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_marginLeft="10dp"
android:layout_weight="1"
android:background="#FF0000"
android:onClick="test"
android:text="Previous"
android:textColor="#ffffff" />
<Button
android:id="#+id/btnNext"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_marginLeft="10dp"
android:layout_weight="1"
android:onClick="test"
android:background="#FF0000"
android:text="Next"
android:textColor="#ffffff" />
</LinearLayout>
This may work for you:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_above="#+id/firstLayout" />
<LinearLayout
android:id="#+id/firstLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#00ffffff"
android:orientation="horizontal"
android:padding="15dp" >
<Button
android:id="#+id/btnPrevious"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_marginLeft="10dp"
android:layout_weight="1"
android:onClick=""
android:text="Previous"
android:textColor="#ffffff" />
<Button
android:id="#+id/btnNext"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_marginLeft="10dp"
android:layout_weight="1"
android:text="Next"
android:textColor="#ffffff" />
</LinearLayout>
</RelativeLayout>
I want to create a view with two parts:
1. Avatar, which is always displayed at right/center_vertial on screen.
2. Name, which is always displayed at left on screen (do not overlap on Avatar).
<?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="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/username" />
</LinearLayout>
<LinearLayout
android:id="#id/avatar"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="right|center_vertical"
android:orientation="vertical" >
<ImageView
android:id="#+id/avatar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center_vertical"
android:scaleType="center"
android:src="#drawable/useravatar" />
</LinearLayout>
</LinearLayout>
The problem is when Name is too long, it overlaps on Avatar. How can I fix this problem?
You should use RelativeLayout and a android:layout_toLeftOf="#id/avatar" attribute for the TextView.
You're better off using a Relative Layout for this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/avatar"
android:text="Some User Name" />
<ImageView
android:id="#+id/avatar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_gravity="right|center_vertical"
android:scaleType="center"
android:src="#drawable/thumbr" />
</RelativeLayout>
I'm encountering a problem where my scrollbar is overlapping with an element from my layout. I'd like for the scroll bar to appear after the edit box: . When adding the scroll bar to different parts of the xml file, I received error messages which I understand to mean that the scrollview had to be the root element. As a result, my code looks like this (when I feel like the scroll view should come after the first linear layout and/or edit box):
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/db1_root"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout style="#style/TitleBar">
<ImageView style="#style/TitleBarLogo"
android:contentDescription="#string/description_logo"
android:src="#drawable/logo" />
<ImageView style="#style/TitleBarSeparator" />
<TextView style="#style/TitleBarText" />
<ImageButton style="#style/TitleBarAction"
android:contentDescription="#string/description_about"
android:src="#drawable/about"
android:onClick="onClickAbout" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:layout_width="match_parent"
android:id="#+id/status"
android:layout_height="wrap_content">
<requestFocus></requestFocus>
</EditText>
<Button android:layout_width="wrap_content" android:text="Ok" android:textColor="#color/title_text" android:layout_gravity="center" android:background="#drawable/custom_button" android:layout_height="wrap_content"></Button>
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical">
<TextView android:textAppearance="?android:attr/textAppearanceMedium" android:layout_width="wrap_content" android:text="" android:id="#+id/updates" android:textSize="14dp" android:layout_height="wrap_content"></TextView>
</LinearLayout>
<TextView android:text="" android:id="#+id/test" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
</LinearLayout>
</LinearLayout>
</ScrollView>
This may work for you: android:scrollbarStyle="outsideOverlay", set this inside the <ScrollView>
Give your LinearLayout or your ScrollView some padding.
I figured this out after chatting with the commonsguy (+1). I misunderstood the android error I received about scroll views and root elements. From my understanding, a scroll view can only have one child. My initial thought was that the scroll view needed to be surround the root element (oops). Here's the fix:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/db1_root"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout style="#style/TitleBar">
<ImageView style="#style/TitleBarLogo"
android:contentDescription="#string/description_logo"
android:src="#drawable/logo" />
<ImageView style="#style/TitleBarSeparator" />
<TextView style="#style/TitleBarText" />
<ImageButton style="#style/TitleBarAction"
android:contentDescription="#string/description_about"
android:src="#drawable/about"
android:onClick="onClickAbout" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:layout_width="match_parent"
android:id="#+id/status"
android:layout_height="wrap_content">
<requestFocus></requestFocus>
</EditText>
<Button
android:layout_width="wrap_content"
android:text="Go"
android:textColor="#color/title_text"
android:layout_gravity="center"
android:id="#+id/communitysubmit"
android:background="#drawable/custom_button"
android:layout_height="wrap_content">
</Button>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<LinearLayout
android:layout_width="match_parent"
android:id="#+id/linearLayoutcommunity"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="wrap_content"
android:text=""
android:id="#+id/updates"
android:textSize="14dp"
android:layout_height="wrap_content">
</TextView>
</LinearLayout>
</ScrollView>
<TextView
android:text=""
android:id="#+id/test"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
</LinearLayout>
</LinearLayout>
Late but I've tried this solution.
Put a Linear layout inside scroll view and then give margin to Linear layout. After that add put your content inside linear layout. Hopefully this will solve issue.
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
>
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginStart="#dimen/_10sdp"
android:layout_marginEnd="#dimen/_10sdp"
>
//your content here
</androidx.appcompat.widget.LinearLayoutCompat>
</androidx.core.widget.NestedScrollView>
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.