【问题标题】:how to display widget at bottom of screen android如何在屏幕底部显示小部件android
【发布时间】:2014-09-29 08:10:25
【问题描述】:

如何在屏幕底部显示小部件按钮。

我想在屏幕底部显示发送按钮

附上截图:

以下是布局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>

选中上面的按钮(发送)我想在屏幕底部显示这个按钮。我该怎么办。我已将 android:layout_gravity=0.0 用于按钮小部件,但不起作用。

【问题讨论】:

  • 你应该使用RelativeLayout而不是你现在使用的LinearLayout,你可以在那里设置android:alignParentBottom="true"
  • 我们不能在线性布局中做到这一点。
  • @vermaraj No..你需要为此使用RelativeLayout。
  • 老兄,这确实是您在任何有关 Android 的教程中找到的第一个内容,请在发布前进行最少的研究!
  • 嗯,这不是一个真正的借口,是吗? Link,Link...都可以在第一页找到here

标签: android android-layout


【解决方案1】:

试试这个方法,希望能帮助你解决问题。

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

【讨论】:

    【解决方案2】:

    轻松使用相对布局而不是线性布局:

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

    在 LinearLayout 中,您将无法执行此操作。希望对您有所帮助。

    【讨论】:

    • 当然你是able to,如果你回答重复的问题,请重新搜索
    【解决方案3】:

    你需要使用相对布局为你的布局文件

    改变

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

    通过

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

    【讨论】:

      猜你喜欢
      • 2021-10-30
      • 2011-08-10
      • 2021-12-28
      • 1970-01-01
      • 2016-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多