如何在Android中并排制作2个按钮

时间:2019-01-06 15:53:16

标签: android android-studio

我正在从事Android项目,需要并排放置2个按钮

3 个答案:

答案 0 :(得分:0)

您的意思是这样

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

答案 1 :(得分:0)

好吧,这很简单,您需要选择xml文件,然后在页面上单击“设计器”,然后可以在预览屏幕上按所需方式移动两个按钮

答案 2 :(得分:0)

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

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