【问题标题】:How to make 2 button side by side in Android如何在Android中并排制作2个按钮
【发布时间】:2019-01-06 15:53:15
【问题描述】:

我正在开发 Android 项目,需要并排制作 2 个按钮

【问题讨论】:

    标签: android android-studio


    【解决方案1】:

    你的意思是这样的

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent">
    
        <Button
          android:id="@+id/button3"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginStart="8dp"
          android:layout_marginTop="8dp"
          android:layout_marginEnd="8dp"
          android:text="Button"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintStart_toStartOf="@+id/guideline13"
          app:layout_constraintTop_toTopOf="parent" />
    
        <Button
          android:id="@+id/button2"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginStart="8dp"
          android:layout_marginTop="8dp"
          android:layout_marginEnd="8dp"
          android:text="Button"
          app:layout_constraintEnd_toStartOf="@+id/guideline13"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toTopOf="parent" />
    
        <android.support.constraint.Guideline
          android:id="@+id/guideline13"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:orientation="vertical"
          app:layout_constraintGuide_percent="0.5" />
    </android.support.constraint.ConstraintLayout>
    

    【讨论】:

      【解决方案2】:

      好的,这很简单,您需要选择您的 xml 文件并在页面左下角单击设计器,然后您可以在预览屏幕上以您想要的方式移动两个按钮

      【讨论】:

        【解决方案3】:

        您可以在线性或相对布局中使用它

         <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:orientation="horizontal">
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Item Name"
        
                />
            <Button
                android:text="Item Name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                />
        </LinearLayout>
        

        【讨论】:

          猜你喜欢
          • 2011-07-29
          • 2019-01-07
          • 2011-01-16
          • 2011-12-25
          • 2015-05-06
          • 1970-01-01
          • 1970-01-01
          • 2021-04-27
          • 2011-06-29
          相关资源
          最近更新 更多