开发者

Android: Button always shown

I wanted to make a button always set at the bottom of the page but will move so it is always shown. The main reason I want this is because when you click into an edit text field the keyboard will pop-up and hide the button. I would like the button to move so it sits above the keyboard when in a field and then will return to the bottom when the keyboard is hidden. Currently I am using a relative layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:orientation="vertical" android:background="#FFFFF0">

    <RelativeLayout android:orientation="vertical"
        android:id="@+id/titlebar1" android:background="#082386"
        android:layout_width="fill_parent" android:layout_height="50dip"
        android:gravity="center">
        <ImageView android:src="@drawable/banner"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:scaleType="fitXY">
        </ImageView>
    </RelativeLayout>


    <Spinner android:layout_height="wrap_content"
        android:layout_below="@+id/titlebar1" android:layout_width="wrap_content"
        android:id="@+id/NewUsedSpinner" android:prompt="@string/NewUsed_prompt"
        android:layout_marginTop="15dip">
    </Spinner>
    <Spinner android:layout_height="wrap_content"
        android:layout_below="@+id/NewUsedSpinner" android:layout_width="wrap_content"
        android:id="@+id/MakeSpinner" android:prompt="@string/Make_prompt">
    </Spinner>
    <Spinner android:layout_height="wrap_content"
        android:layout_below="@+id/MakeSpinner" android:layout_width="wrap_content"
        android:id="@+id/ModelSpinner" android:promp开发者_JAVA百科t="@string/Model_prompt"></Spinner>
    <Spinner android:layout_height="wrap_content"
        android:layout_below="@+id/NewUsedSpinner" android:layout_width="wrap_content"
        android:id="@+id/TrimSpinner" android:prompt="@string/Trim_prompt"></Spinner>
    <Spinner android:layout_height="wrap_content"
        android:layout_width="wrap_content" android:id="@+id/PriceSpinner"
        android:layout_below="@+id/TrimSpinner" android:prompt="@string/Price_prompt"
        android:layout_marginBottom="5dip"></Spinner>



    <TextView android:text="Search within the radius of:"
        android:layout_below="@+id/PriceSpinner" android:id="@+id/textView1"
        android:layout_width="wrap_content" android:layout_alignLeft="@+id/FilterZip"
        android:layout_height="wrap_content" android:textColor="#000"
        android:layout_marginTop="5dip"></TextView>



    <Spinner android:id="@+id/ZipSpinner" android:layout_width="120dip"
        android:layout_below="@+id/textView1" android:layout_height="wrap_content"
        android:prompt="@string/Zip_prompt"></Spinner>
    <EditText android:layout_width="fill_parent"
        android:layout_below="@+id/textView1" android:layout_toRightOf="@+id/ZipSpinner"
        android:layout_height="wrap_content" android:text="Zip" android:id="@+id/FilterZip"
        android:maxLength="5" android:numeric="integer"></EditText>


    <Button android:layout_height="50dip" android:id="@+id/FilterSearchbtn"
        android:layout_alignParentBottom="true" android:layout_width="fill_parent"
        android:text="Search" android:layout_below="@+id/ZipSpinner"
        android:background="@drawable/yellow_btn" android:textStyle="bold"></Button>



</RelativeLayout>


In your Android manifest you would add this to your activity:

<activity android:name=".YourActivity"
        android:windowSoftInputMode="adjustResize"

Here's the official documentation: http://developer.android.com/resources/articles/on-screen-inputs.html

Maybe try alignParentBottom="true" on the button so that it will always be on the bottom, you'll have to fiddle with your layout.


(1) If we want to only adjust the screen without view which has (alignParentBottom="true") in relative layout then set below line in activity tag in manifest.xml

android:windowSoftInputMode="adjustPan"

(2) If we want to adjust the whole relative layout with the view which has (alignParentBottom="true") in relative layout then set below line in activity tag in manifest.xml

android:windowSoftInputMode="adjustResize"

(3) If we don't want to adjust the whole relative layout without the view which has (alignParentBottom="true") in relative layout then set below line in activity tag in manifest.xml

android:windowSoftInputMode="adjustPan|adjustResize"

(4) If we remove line android:windowSoftInputMode from the manifest.xml then it will behave like (2) option

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜