how to display widget at bottom of screen android

How to display widget button at bottom of screen.

I want to display Send button at the bottom of the screen.

Attaching the screenshot :

The following the is the layout xml :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/LinearLayout2"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:orientation="vertical" >

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content" 
        android:hint="@string/to"/>

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content" 
        android:hint="@string/subject"/>

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content" 
        android:hint="@string/message"/>

    <Button
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:text="@string/send"/>

</LinearLayout>

Check the button (Send) above i want to display this button at bottom of the screen. what should i do. I have used android:layout_gravity=0.0 for the button widget, but not works.


Use Relative Layout instead of LinearLayout easily:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/LinearLayout2"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:orientation="vertical" >

    <EditText
        android:id="@+id/to"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" 
        android:hint="to"/>

    <EditText
        android:id="@+id/sub"
        android:layout_below="@id/to"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" 
        android:hint="subject"/>

    <EditText
        android:id="@+id/msg"
        android:layout_below="@id/sub"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" 
        android:hint="message"/>

    <Button
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:text="send"/>

</RelativeLayout>

In LinearLayout, you won't be able to do this. Hope it helps.


试试这种方式,希望这会帮助你解决你的问题。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/LinearLayout2"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:orientation="vertical" >

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/to"/>

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/subject"/>

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/message"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:gravity="bottom|right">
        <Button
            android:layout_width="100dp"
            android:layout_height="wrap_content"
            android:text="@string/send"/>
    </LinearLayout>

</LinearLayout>

You need to use Relative Layout For you Layout file

and Change

<Button
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:text="@string/send"/>

Via

<Button
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:text="@string/send"/>
链接地址: http://www.djcxy.com/p/93216.html

上一篇: 在视图的底部放置一个线性布局

下一篇: 如何在屏幕底部显示小部件android