Android 线性布局,带有不同高度的儿童的布局和重量

Android 线性布局,带有不同高度的儿童的布局和重量,android,android-linearlayout,Android,Android Linearlayout,我的图像按钮的高度是40像素,但我的图库的高度要大得多。现在,我的图像按钮占据了它们所提供的全部空间,并且与我的图库高度相同。有没有办法在保持水平布局的同时保持按钮的原始尺寸 <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:orienta

我的图像按钮的高度是40像素,但我的图库的高度要大得多。现在,我的图像按钮占据了它们所提供的全部空间,并且与我的图库高度相同。有没有办法在保持水平布局的同时保持按钮的原始尺寸

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:orientation="horizontal"
        android:paddingTop="20dp" >

        <ImageButton
            android:id="@+id/left_arrow"
            android:layout_weight="3"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/shared_arrow_left_button_selector"
            android:scaleType="fitCenter" />

        <Gallery
            android:id="@+id/gallery"
            android:focusable="true"
        android:focusableInTouchMode="true"
        android:layout_weight="1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:spacing="15dp" />

        <ImageButton
            android:id="@+id/right_arrow"
            android:layout_weight="3"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/shared_arrow_right_button_selector"
            android:scaleType="fitCenter" />
    </LinearLayout>

删除ImageButtons中的布局权重=3,这是显示大于Gallery的图像按钮的原因

我认为您不知道如何使用layout_weight属性,所以您不知道如何解决这个问题。首先了解布局和重量

如果你有任何疑问,请随时问我

在图像按钮和多媒体资料中使用下面的行,这将是很好的

android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"

删除“权重”属性,并设置按钮的宽度和高度以包装内容
您正在申请

android:layout_width="match_parent"
android:layout_height="match_parent"
如果您只想让ImageButtons包裹其原始尺寸,只需将其更改为
wrap\u content
,并删除
layout\u weight
属性即可。另外,当您将
layout\u weight=“1”
应用于多媒体资料时,只需更改
android:layout\u width=“0dp”
,因为宽度将由
layout\u weight
属性本身管理。你的最终布局应该是

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="horizontal"
    android:paddingTop="20dp" >

    <ImageButton
        android:id="@+id/left_arrow"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scaleType="fitCenter" />

    <Gallery
        android:id="@+id/gallery"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:spacing="15dp" />

    <ImageButton
        android:id="@+id/right_arrow"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scaleType="fitCenter" />

</LinearLayout>


能否添加LinearLayout的起始标记,以便我更好地理解它?请使用您获得的屏幕截图进行更新…我认为权重用于动态调整视图宽度
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="horizontal"
    android:paddingTop="20dp" >

    <ImageButton
        android:id="@+id/left_arrow"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scaleType="fitCenter" />

    <Gallery
        android:id="@+id/gallery"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:spacing="15dp" />

    <ImageButton
        android:id="@+id/right_arrow"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scaleType="fitCenter" />

</LinearLayout>