开发者

How to dock the relative layout to the botton of the screen

开发者 https://www.devze.com 2023-02-28 13:06 出处:网络
I want to dock the button always to the bottom of screen. I am have changed the android:gravity=\"bottom\" to bottom.

I want to dock the button always to the bottom of screen. I am have changed the android:gravity="bottom" to bottom.

I am confused with android:gravity and layout gravity.Well , my question is how can i dock the buttons to the bottom ?

    <Spinner android:id="@+id/alphabets" android:layout_height="wrap_content"
        android:layout_width="match_parent">
    </Spinner>
    <TextView android:layout_width="wrap_content" android:text="TextView"
        android:layout_height="wrap_content" android:id="@+id/textView1"
        android:editable="false" android:textSize="5开发者_开发知识库0sp" android:gravity="center_horizontal"
        android:layout_gravity="center_horizontal">
    </TextView>

    <RelativeLayout android:id="@+id/relativeLayout1"
        android:layout_height="wrap_content" android:gravity="bottom"
        android:layout_width="fill_parent" android:layout_gravity="fill">
        <ImageButton android:layout_width="wrap_content"
            android:id="@+id/imageButton1" 
            android:src="@drawable/arrow_button_left"
            android:layout_height="wrap_content" />
        <ImageButton android:layout_width="wrap_content"
            android:id="@+id/imageButton2" 
            android:src="@drawable/arrow_button_right"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true" />
    </RelativeLayout>
</LinearLayout>

How to dock the relative layout to the botton of the screen


<RelativeLayout 
        android:layout_height="wrap_content" 
        android:layout_width="fill_parent" >

<RelativeLayout android:id="@+id/relativeLayout1"
        android:layout_height="wrap_content" 
        android:layout_width="fill_parent" android:layout_alignParentBottom="true">

<ImageButton android:layout_width="wrap_content"
            android:id="@+id/imageButton1" 
            android:src="@drawable/arrow_button_left"
            android:layout_height="wrap_content" />
        <ImageButton android:layout_width="wrap_content"
            android:id="@+id/imageButton2" 
            android:src="@drawable/arrow_button_right"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true" />

</RelativeLayout>
</RelativeLayout>

instead taking Linear layout take Relative Layout as parent


Vertical gravity doesn't work in vertical linear layout. You should fill space between relative layout and text view somehow. For example set android:layout_height="fill_parent" for text view or put some dummy view with layout_height="fill_parent" between them.


try this one..

<RelativeLayout android:id="@+id/relativeLayout1"
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent" android:layout_alignParentBottom="true">
<ImageButton android:layout_width="wrap_content"
        android:id="@+id/imageButton1" 
        android:src="@drawable/arrow_button_left"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_height="wrap_content" />
    <ImageButton android:layout_width="wrap_content"
        android:id="@+id/imageButton2" 
        android:src="@drawable/arrow_button_right"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true" />
       </RelativeLayout> 


Try this also if you are planning to have listview with some selectors in footer docking at bottom. Take care of android:layout_above and android:layout_alignParentTop for relativeLayout1 .

<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="vertical" >

    <RelativeLayout android:id="@+id/relativeLayout1"
            android:layout_height="wrap_content" 
            android:layout_width="fill_parent" 
            android:layout_alignParentTop="true"
            android:layout_above="@+id/footerRow" >

        <ListView
            android:id="@+id/summaryListView"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"

            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:choiceMode="singleChoice"
            android:drawSelectorOnTop="true" >

        </ListView>

    </RelativeLayout>

    <TableRow
        android:id="@+id/footerRow"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:baselineAligned="true"
        android:layout_alignParentBottom="true" >

        <Spinner
            android:id="@+id/_ddlPeriod"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:entries="@array/Period_Selector"
             />
    </TableRow>

</RelativeLayout>
0

精彩评论

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

关注公众号