繁体   English   中英

如何在屏幕底部显示三个按钮,例如android中的facebook?

[英]How to show three buttons at the bottom of the screen like facebook in android?

我正在使用android,并且需要进行XML设计,在该设计中,我需要始终在屏幕底部始终水平放置三个按钮。 就像android中的facebook应用程序一样,它们在屏幕底部有三个按钮(状态,照片,签入)-同样,我的应用程序中也总是需要三个按钮。

这种布局的设计将是什么?

我尝试了下面的XML设计,但是它无法正常工作,而且它们都是垂直的-

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

    <TextView
        android:id="@+id/textView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="@string/cow"
        android:layout_weight="0"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="1"
        android:gravity="center|bottom"
        android:orientation="vertical" >

        <Button
            android:id="@+id/button1"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="145dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal|center"
            android:text="ButtonA" />

        <Button
            android:id="@+id/button2"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="145dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal|center"
            android:text="ButtonB" />

        <Button
            android:id="@+id/button3"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="145dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal|center"
            android:text="ButtonC" />
    </LinearLayout>

</LinearLayout>

我只需要在屏幕底部水平显示三个按钮,就像facebook总是并排显示(彼此触摸)一样。 这可能吗?

按钮名称可以是ButtonA, ButtonB and ButtonC

使用以下布局,我认为它可以帮助您

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

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0"
        android:gravity="center"
        android:text="cow"
        android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/button1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="ButtonA" />

    <Button
        android:id="@+id/button2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="ButtonB" />

    <Button
        android:id="@+id/button3"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="ButtonC" />
</LinearLayout>

我不知道您最终需要如何调整,因此我将其保留为通用名称:

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

    <TextView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <View
            android:layout_width="0dp"
            android:layout_height="1dp"
            android:layout_weight="2" />

        <Button
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1" />

        <Button
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1" />

        <Button
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1" />

        <View
            android:layout_width="0dp"
            android:layout_height="1dp"
            android:layout_weight="2" />

    </LinearLayout>        

</LinearLayout>

也许您可以使用具有Header-Footer-Content结构的布局,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<!-- Header aligned to top -->
<RelativeLayout
    android:id="@+id/header"
    android:layout_alignParentTop="true"
    ...>
</RelativeLayout>

<!-- Footer aligned to bottom -->
<RelativeLayout
    android:id="@+id/footer"
    android:layout_alignParentBottom="true"
    ...>
   <!-- put your layout and buttons here -->
</RelativeLayout>

<!-- Content below header and above footer -->
<RelativeLayout
    android:id="@+id/content"
    android:layout_above="@id/footer"
    android:layout_below="@id/header"
    ...>
</RelativeLayout>

您可以随意删除碎片。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM