如何让这个 android 按钮布局单行 6 个按钮填满整个屏幕

How to make this android button layout 6 buttons in a single row fills whole screen

这是我想要的图片。它们需要根据屏幕尺寸进行缩放。如果屏幕尺寸为 1920x1080p,它们应该看起来很完美。

这是我尝试过的方法,但失败了,什么都看不到

    <ImageButton
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/imageButton_register"
    android:background="@null"
    android:src="@drawable/bgbutton_1"
    android:adjustViewBounds="true"
    android:scaleType="centerCrop"
    android:layout_centerInParent="true"
    />

<ImageButton
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/imageButton_register2"
    android:background="@null"
    android:src="@drawable/button1"
    android:adjustViewBounds="true"
    android:scaleType="centerCrop"
    android:layout_centerInParent="true"
    />

<ImageButton
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/imageButton_register3"
    android:background="@null"
    android:src="@drawable/button2"
    android:adjustViewBounds="true"
    android:scaleType="centerCrop"
    android:layout_centerInParent="true"
    />

我正在使用 android 工作室并且 api 在 windows 8.1

上是 9

图片的确切尺寸为 1080x560 像素和 1080x200 像素

使用线性布局给orientation=vertical 把你的图片按钮放在里面,给你的线性布局 weight_sum=100,然后你可以给你的图片按钮按百分比 weight 就像如果你有 2 个图像按钮给每个图像按钮 weight=50,如果你有 5 个图像按钮给每个图像按钮 weight=20 使用这个:

<LinearLayout
        android:id="@+id/linearButtons"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:weightSum="100" >

<ImageButton
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/imageButton_register"
        android:src="@drawable/bgbutton_1"
        android:adjustViewBounds="true"
        android:scaleType="centerCrop"
        android:layout_weight="16.6"/>

<ImageButton
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/imageButton_register2"
        android:src="@drawable/button1"
        android:adjustViewBounds="true"
        android:scaleType="centerCrop"
        android:layout_weight="16.6"/>

<ImageButton
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/imageButton_register"
        android:src="@drawable/bgbutton_1"
        android:adjustViewBounds="true"
        android:scaleType="centerCrop"
        android:layout_weight="16.6"/>

<ImageButton
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/imageButton_register2"
        android:src="@drawable/button1"
        android:adjustViewBounds="true"
        android:scaleType="centerCrop"
        android:layout_weight="16.6"/>

<ImageButton
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/imageButton_register"
        android:src="@drawable/bgbutton_1"
        android:adjustViewBounds="true"
        android:scaleType="centerCrop"
        android:layout_weight="16.6"/>

<ImageButton
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/imageButton_register2"
        android:src="@drawable/button1"
        android:adjustViewBounds="true"
        android:scaleType="centerCrop"
        android:layout_weight="16.6"/>
</LinearLayout>

试试这个代码:

<LinearLayout
        android:id="@+id/ll_main_view_about_us_screen"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:weightSum="6" >

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:layout_gravity="center"
            android:layout_weight="1"
            android:background="@color/text_black" />

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:layout_gravity="center"
            android:layout_weight="1"
            android:background="@color/text_black" />

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:layout_gravity="center"
            android:layout_weight="1"
            android:background="@color/text_black" />

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:layout_gravity="center"
            android:layout_weight="1"
            android:background="@color/text_black" />

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:layout_gravity="center"
            android:layout_weight="1"
            android:background="@color/text_black" />

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:layout_gravity="center"
            android:layout_weight="1"
            android:background="@color/text_black" />
</LinearLayout>