android - Android 布局问题

标签 android android-layout

我很难让第二个子线性布局中的 2 个按钮按我希望的方式显示...我希望它们居中,在同一行上,但它们显示为左对齐并在同一行上.谁能帮我解决这个问题?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/black"
    android:orientation="vertical">

  <LinearLayout
      android:id="@+id/splash"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:orientation="vertical">

    <ImageView
      android:id="@+id/imageLogo1"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:adjustViewBounds="true"
      android:cropToPadding="true"
      android:scaleType="fitXY"
      android:src="@drawable/isi_logo"
      android:paddingLeft="50sp"
      android:paddingRight="50sp"
      android:paddingTop="20sp"/>

    <ImageView
      android:id="@+id/imageLogo2"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:adjustViewBounds="true"
      android:cropToPadding="true"
      android:scaleType="fitXY"
      android:src="@drawable/sa_logo"
      android:paddingLeft="100sp"
      android:paddingRight="100sp"
      android:paddingBottom="20sp"/>

  </LinearLayout>

  <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:layout_gravity="center">

    <Button  
      android:id="@+id/buttonScores"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:width="100sp"
      android:text="@string/scores"/>

    <Button
      android:id="@+id/buttonStart"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:width="100sp"
      android:text="@string/test"/>

  </LinearLayout>

</LinearLayout>

最佳答案

尝试使用 android:gravity="center"而不是 android:layout_gravity="center"

关于android - Android 布局问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2678098/

相关文章:

java - 给定 GPS 地理位置,如何查找给定 x 米半径内的纬度和经度

android - Android中的简单语音命令

android - 在指定的SDK位置下没有找到Android SDK

android - 从微调器中删除文本

android - 在使用 alignParentBottom 的相对布局中,如何在我的代码中的约束布局中使用相同的布局?

android - 在 Android 中向用户显示提示的新样式

android - 带椭圆大小的垂直 TextView 和所有其他默认 TextView 功能支持

java - 查询Firestore数据并向与查询匹配的所有文档添加一个字段

Android Studio 中的 Android Lollipop 系统图标

android - 使用 XML 向约束布局中的 TextView 添加边距