开发者

How to place Relative Layout at the bottom always

MY XMl code looks like :

 <?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="wrap_content">

  <ScrollView 
xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="430dp"
  android:fadingEdge="none"
  >    
  <LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:background="@drawable/descriptionanth"
  android:orientation="vertical"
  android:id="@+id/searchjobslayout"
  >
      <ImageView android:id="@+id/homeimage_one" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_width="fill_parent" android:background="@drawable/logoblack"></ImageView>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent" android:layout_height="match_parent">




     <TextView 
     android:id="@+id/keywords"
     android:text="Search by keyword:"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:textSize="14sp"
     android:textStyle="bold"
      android:textColor="#000000"
     android:layout_marginLeft="10dp"
     ></TextView>

     <EditText
      android:id="@+id/keywordsedit"
      android:hint="  Enter KeyWords"
      android:layout_width="fill_parent"
      android:layout_height="32dp"
      android:layout_marginLeft="10dp"
      android:layout_marginRight="10dp"
      android:textSize="14sp"
      android:background="@drawable/text_field"
      android:layout_marginTop="5dp"
      android:textColorHint="#FFFFFF"
      android:paddingLeft="10dp"
      android:textColor="#000000"
     ></EditText>

      <Button
     android:id="@+id/search"
     android:text="Search"
     android:layout_width="fill_parent"
     android:layout_height="35dp"
     android:textColor="#FFFFFF"
     android:background="@drawable/buttonclick"
     android:layout_marginLeft="10dp"
     android:layout_marginRight="10dp"
     android:layout_marginTop="5dp"

     android:textSize="20sp"
     ></Button>

     <TextView 
     android:id="@+id/browseby"
     android:text="Browse by:"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:textSize="14sp"
     android:textStyle="bold"
      android:textColor="#000000"
     android:layout_marginLeft="10dp"
     android:paddingTop="10dp"></TextView>




    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"

    >


    <Button 
     android:id="@+id/jobsbycity"
     android:text="City"
     android:layout_width="fill_parent"
     android:layout_height="30dp"

     android:textColor="#FFFFFF"
     android:background="@drawable/buttonclick"

     android:layout_marginLeft="10dp"
     android:layout_marginRight="10dp"
     android:layout_marginTop="5dp"
     android:textStyle="bold"
     android:textSize="15sp"
     ></Button>


    <Button 
     android:id="@+id/jobsbytype"
     android:text="Category"
     android:layout_width="fill_parent"
     android:layout_height="30dp"
     android:textColor="#FFFFFF"

     android:background="@drawable/buttonclick"
     android:layout_below="@id/jobsbycity"
     android:layout_marginLeft="10dp"
     android:layout_marginRight="10dp"
     android:textStyle="bold"
     android:layout_marginTop="5dp"

     android:textSize="15sp"
     ></Button>

      <TextView 
     android:id="@+id/signin"
     android:text="Signed in as"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:textSize="12sp"

     android:textColor="#000000"
     android:layout_centerInParent="true"
     android:gravity="center_horizontal"
     android:layout_below="@id/jobsbytype"
     android:paddingTop="10dp"></TextView>

     <TextView 
     android:id="@+id/signinas"
     android:text="mail_id"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:textSize="12sp"
     android:layout_centerInParent="true"
     android:textColor="#000000"

     android:gravity="center_horizontal"
     android:layout_below="@id/signin"
     android:paddingTop="5dp"></TextView>

     <TextView 
     android:id="@+id/logout"
     android:text="Sign out"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:textSize="13sp"

     android:gravity="center_vertical"
     android:textColor="#000000"
      android:layout_below="@id/signinas"
     android:layout_centerInParent="true"
     android:layout_marginTop="20dp"
     android:textStyle="bold" ></TextView>
    </RelativeLayout>





    </LinearLayout>

     <TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"   
    />

    <TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"   
    />

    <TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"   
    />

    <TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"   
    />

    <TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"   
    />

    <TextView  
    android:layout_width="fill_parent" 
    android:layout_he开发者_开发知识库ight="wrap_content"   
    />

    <TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"   
    />

    <TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"   
    />

    <TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"   
    />

    <TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"   
    />

     <TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"   
    />

    <TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"   
    />
    <TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"   
    />

     <TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"   
    />

     <TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"   
    />

     <TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"   
    />

     <TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"   
    />

     <TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"   
    />

     <TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"   
    />

     <TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"   
    />

     <TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"   
    />
    </LinearLayout>
    </ScrollView>

  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/tabbarbottom"
    android:layout_gravity="bottom"


    >

  <Button
     android:id="@+id/jobs"
     android:text="About Us"
     android:layout_width="100dp"
     android:layout_height="fill_parent"
     android:textColor="@drawable/white"
     android:background="@android:color/transparent"

     android:layout_alignParentBottom="true"
     android:textStyle="bold"
     android:textSize="12.5sp"
     ></Button>

     <Button
     android:id="@+id/aboutus"
     android:text="Value"
     android:layout_width="100dp"
     android:layout_height="fill_parent"
      android:textColor="@drawable/white"
     android:layout_toRightOf="@id/jobs"
     android:background="@android:color/transparent"
     android:layout_centerHorizontal="true"
      android:layout_centerVertical="true"
      android:layout_alignParentBottom="true"
      android:layout_marginLeft="10dp"
      android:textStyle="bold"
       android:textSize="12.5sp"
     ></Button>

     <Button
     android:id="@+id/benefits"
     android:text="History"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:textColor="@drawable/white"
     android:layout_toRightOf="@id/aboutus"
     android:background="@android:color/transparent"
     android:layout_centerVertical="true"
     android:layout_alignParentBottom="true"
     android:textStyle="bold"
     android:textSize="12.5sp"
     ></Button>

    </RelativeLayout>




</LinearLayout>

I want to place the relative layout (last relative layout which having 3 buttons it, after scrollview ) at the bottom my screen. but its not happening

what to do??

Edited: The happening is i statically placed the relative layout by specifying padding, when running in portrait mode i made it fix at bottom but when i changed to landscape its not at bottom. How to place relativelayout in bottom in either cases??

Thanks


Add following line to your Relative layout

android:layout_alignParentBottom="true" 

This must be work.

Happy coding.


Here the solution I tested and which works :

<?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">

    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent" android:layout_height="100dp"
        android:layout_weight="1.0" android:fadingEdge="none">
    ...
    </ScrollView>

    <RelativeLayout android:orientation="horizontal" 
        android:layout_width="fill_parent" android:layout_height="60dip" 
        android:background="@drawable/tabbarbottom">

        <Button android:id="@+id/jobs" android:text="About Us"
            android:layout_width="100dp" android:layout_height="fill_parent"
            ...></Button>

        <Button android:id="@+id/aboutus" android:text="Value"
            android:layout_width="100dp" android:layout_height="fill_parent"
            ...></Button>

        <Button android:id="@+id/benefits" android:text="History"
            android:layout_width="fill_parent" android:layout_height="fill_parent" ...></Button>

    </RelativeLayout>
</LinearLayout>
  • The first LinearLayout should have layout_height="fill_parent". This way it takes up the whole screen.
  • The ScrollView should have a small fixed height, and an extra android:layout_weight="1.0" : it will take up whatever space is remaining.
  • The RelativeLayout should have a fixed height (it will always take up the same space at the bottom of the screen), and the Buttons inside of it should have layout_height="fill_parent" (to have the same height as the RelativeLayout).


Make parent layout as relative layout. layout which contain button put that on bottom using

android:layout_alignParentBottom="true"

This will work


In the ScrollView

android:fillViewport="false"


@Udaykiran Hey Your Code for XMl is ok please check here i put your code with some change and i found only one change in this Relative Layout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:orientation="horizontal" 
                                   android:layout_width="fill_parent"
                android:layout_height="wrap_content">

please change this than try

here is xml with with out resources

<?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="wrap_content" android:orientation="vertical">

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="430dp"
    android:fadingEdge="none">
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent" android:layout_height="wrap_content"
        android:background="@drawable/splash_screen_large_long_land"
        android:orientation="vertical" android:id="@+id/searchjobslayout">
        <ImageView android:id="@+id/homeimage_one"
            android:layout_height="wrap_content" android:layout_gravity="center_horizontal"
            android:layout_width="fill_parent"></ImageView>

        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" android:orientation="vertical">

            <TextView android:id="@+id/keywords" android:text="Search by keyword:"
                android:layout_width="wrap_content" android:layout_height="wrap_content"
                android:textSize="14sp" android:textStyle="bold" android:textColor="#000000"
                android:layout_marginLeft="10dp"></TextView>

            <EditText android:id="@+id/keywordsedit" android:hint="  Enter KeyWords"
                android:layout_width="fill_parent" android:layout_height="32dp"
                android:layout_marginLeft="10dp" android:layout_marginRight="10dp"
                android:textSize="14sp" android:layout_marginTop="5dp"
                android:textColorHint="#FFFFFF" android:paddingLeft="10dp"
                android:textColor="#000000"></EditText>

            <Button android:id="@+id/search" android:text="Search"
                android:layout_width="fill_parent" android:layout_height="35dp"
                android:textColor="#FFFFFF" android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp" android:layout_marginTop="5dp"
                android:textSize="20sp"></Button>

            <TextView android:id="@+id/browseby" android:text="Browse by:"
                android:layout_width="wrap_content" android:layout_height="wrap_content"
                android:textSize="14sp" android:textStyle="bold" android:textColor="#000000"
                android:layout_marginLeft="10dp" android:paddingTop="10dp"></TextView>




            <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:orientation="horizontal" android:layout_width="fill_parent"
                android:layout_height="wrap_content">


                <Button android:id="@+id/jobsbycity" android:text="City"
                    android:layout_width="fill_parent" android:layout_height="30dp"

                    android:textColor="#FFFFFF" android:layout_marginLeft="10dp"
                    android:layout_marginRight="10dp" android:layout_marginTop="5dp"
                    android:textStyle="bold" android:textSize="15sp"></Button>


                <Button android:id="@+id/jobsbytype" android:text="Category"
                    android:layout_width="fill_parent" android:layout_height="30dp"
                    android:textColor="#FFFFFF" android:layout_below="@id/jobsbycity"
                    android:layout_marginLeft="10dp" android:layout_marginRight="10dp"
                    android:textStyle="bold" android:layout_marginTop="5dp"
                    android:textSize="15sp"></Button>

                <TextView android:id="@+id/signin" android:text="Signed in as"
                    android:layout_width="wrap_content" android:layout_height="wrap_content"
                    android:textSize="12sp" android:textColor="#000000"
                    android:layout_centerInParent="true" android:gravity="center_horizontal"
                    android:layout_below="@id/jobsbytype" android:paddingTop="10dp"></TextView>

                <TextView android:id="@+id/signinas" android:text="mail_id"
                    android:layout_width="wrap_content" android:layout_height="wrap_content"
                    android:textSize="12sp" android:layout_centerInParent="true"
                    android:textColor="#000000" android:gravity="center_horizontal"
                    android:layout_below="@id/signin" android:paddingTop="5dp"></TextView>

                <TextView android:id="@+id/logout" android:text="Sign out"
                    android:layout_width="wrap_content" android:layout_height="wrap_content"
                    android:textSize="13sp" android:gravity="center_vertical"
                    android:textColor="#000000" android:layout_below="@id/signinas"
                    android:layout_centerInParent="true" android:layout_marginTop="20dp"
                    android:textStyle="bold"></TextView>
            </RelativeLayout>





        </LinearLayout>

        <TextView android:layout_width="fill_parent"
            android:layout_height="wrap_content" />

        <TextView android:layout_width="fill_parent"
            android:layout_height="wrap_content" />

        <TextView android:layout_width="fill_parent"
            android:layout_height="wrap_content" />

        <TextView android:layout_width="fill_parent"
            android:layout_height="wrap_content" />

        <TextView android:layout_width="fill_parent"
            android:layout_height="wrap_content" />

        <TextView android:layout_width="fill_parent"
            android:layout_height="wrap_content" />

        <TextView android:layout_width="fill_parent"
            android:layout_height="wrap_content" />

        <TextView android:layout_width="fill_parent"
            android:layout_height="wrap_content" />

        <TextView android:layout_width="fill_parent"
            android:layout_height="wrap_content" />

        <TextView android:layout_width="fill_parent"
            android:layout_height="wrap_content" />

        <TextView android:layout_width="fill_parent"
            android:layout_height="wrap_content" />

        <TextView android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
        <TextView android:layout_width="fill_parent"
            android:layout_height="wrap_content" />

        <TextView android:layout_width="fill_parent"
            android:layout_height="wrap_content" />

        <TextView android:layout_width="fill_parent"
            android:layout_height="wrap_content" />

        <TextView android:layout_width="fill_parent"
            android:layout_height="wrap_content" />

        <TextView android:layout_width="fill_parent"
            android:layout_height="wrap_content" />

        <TextView android:layout_width="fill_parent"
            android:layout_height="wrap_content" />

        <TextView android:layout_width="fill_parent"
            android:layout_height="wrap_content" />

        <TextView android:layout_width="fill_parent"
            android:layout_height="wrap_content" />

        <TextView android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
    </LinearLayout>
</ScrollView>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:layout_gravity="bottom">

    <Button android:id="@+id/jobs" android:text="About Us"
        android:layout_width="100dp" android:layout_height="fill_parent"
        android:background="@android:color/transparent"

        android:layout_alignParentBottom="true" android:textStyle="bold"
        android:textSize="12.5sp"></Button>

    <Button android:id="@+id/aboutus" android:text="Value"
        android:layout_width="100dp" android:layout_height="fill_parent"
        android:layout_toRightOf="@id/jobs" android:background="@android:color/transparent"
        android:layout_centerHorizontal="true" android:layout_centerVertical="true"
        android:layout_alignParentBottom="true" android:layout_marginLeft="10dp"
        android:textStyle="bold" android:textSize="12.5sp"></Button>

    <Button android:id="@+id/benefits" android:text="History"
        android:layout_width="fill_parent" android:layout_height="fill_parent"
        android:layout_toRightOf="@id/aboutus" android:background="@android:color/transparent"
        android:layout_centerVertical="true"
        android:layout_alignParentBottom="true" android:textStyle="bold"
        android:textSize="12.5sp"></Button>

</RelativeLayout>

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜