简体   繁体   English

Android版式:底部的3个按钮

[英]Android Layout: 3 buttons at the bottom

I am designing a layout which has 3 buttons at the bottom very adjacent to each other. 我正在设计一种布局,该布局的底部有3个按钮,彼此非常相邻。 Because I want to add some more button in the middle of the screen too so what I am doing is I set up a whole screen as a Relative Layout and to get the 3 buttons at the bottom I add a Linear Layout to contain those 3 buttons. 因为我也想在屏幕中间添加更多按钮,所以我要做的是将整个屏幕设置为相对布局,并在底部获得3个按钮,我添加了包含这3个按钮的线性布局。 However, it gets stuck. 但是,它卡住了。 The button does not show 3 buttons in the bottom. 该按钮底部没有显示3个按钮。 Here is my xml layout file 这是我的xml布局文件

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



    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:orientation="vertical" 
        android:weightSum="1">

           <Button
        android:id="@+id/button1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:text="Button1"
        android:layout_weight="0.3" />
          <Button
        android:id="@+id/button2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="Button2" 
         android:layout_weight="0.3"/>
                              <Button
        android:id="@+id/button3"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="Button3"
         android:layout_weight="0.3" />

    </LinearLayout>

    <Button
        android:id="@+id/button4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignTop="@+id/linearLayout1"
        android:layout_marginTop="16dp"
        android:layout_toRightOf="@+id/linearLayout1"
        android:text="Button" />

    <Button
        android:id="@+id/button5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/button4"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/button4"
        android:layout_marginTop="20dp"
        android:text="Button" />

    <Button
        android:id="@+id/button6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/button5"
        android:layout_marginTop="24dp"
        android:text="Button" />

</RelativeLayout>

我认为您的问题来自三个按钮上的android:layout_width="0dp"

   <LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:orientation="vertical" 
    android:weightSum="1">

android:orientation="vertical" change this to horizontal android:layout_width="wrap_content" change this to fill_parent android:orientation =“ vertical”更改为水平android:layout_width =“ wrap_content”更改为fill_parent

   <Button
    android:id="@+id/button1"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:text="Button1"
    android:layout_weight="0.3" />

android:layout_alignParentLeft="true", and i dont think this does work in a linearlayout . android:layout_alignParentLeft =“ true”,我认为这在linearlayout中不起作用。

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

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