Android:ImageView 重叠

Android : ImageView overlapping

我有五个 ImageView (ImageButtons),我想在一行中显示它,但是当我在小型设备上时,我的最后一张图片被裁剪了?

我该如何解决?

有没有办法检测屏幕宽度?

|一个|乙 |丙 | D | E |

在我的 RelativeLayout xml 文件中:

<ImageButton
        android:id="@+id/mFooterProfileImg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toEndOf="@+id/mFooterMembersImg"
        android:layout_alignParentEnd="true"
        android:background="@drawable/icon_bar_profile"
        android:contentDescription="@string/footer_img_profile" />

    <ImageButton
        android:id="@id/mFooterMembersImg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toEndOf="@+id/mFooterCameraImg"
        android:background="@drawable/icon_bar_members"
        android:contentDescription="@string/footer_img_members" />

    <ImageButton
        android:id="@id/mFooterCameraImg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toEndOf="@+id/mFooterMediaImg"
        android:background="@drawable/icon_bar_camera"
        android:contentDescription="@string/footer_img_camera" />

    <ImageButton
        android:id="@id/mFooterMediaImg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toEndOf="@+id/mFooterHomeImg"
        android:background="@drawable/icon_bar_medias"
        android:contentDescription="@string/footer_img_media" />

    <ImageButton
        android:id="@id/mFooterHomeImg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:background="@drawable/icon_bar_home"
        android:contentDescription="@string/footer_img_home" />

在我看来,正确的做法是创建线性布局, 确保方向是水平的。 然后为每个 imageButton 传递 layout_width="0dp", 并为每个 imageButton 分配 layout_weight="20"

这为每张图片提供了 20% 的宽度。

就像魔像说的那样

我将 Der Golem 的评论作为答案发布,只是为了帮助您。在您的 xml 中使用以下代码来实现您的 objective:

<LinearLayout

android:layout_width = "match_parent"
android:layout_height= "match_parent">

<ImageButton
        android:id="@+id/mFooterProfileImg"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight = "1"

        android:background="@drawable/icon_bar_profile"
        android:contentDescription="@string/footer_img_profile" />

    <ImageButton
        android:id="@id/mFooterMembersImg"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
      android:layout_weight = "1"
        android:background="@drawable/icon_bar_members"
        android:contentDescription="@string/footer_img_members" />

    <ImageButton
        android:id="@id/mFooterCameraImg"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
       android:layout_weight = "1"
        android:background="@drawable/icon_bar_camera"
        android:contentDescription="@string/footer_img_camera" />

    <ImageButton
        android:id="@id/mFooterMediaImg"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
       android:layout_weight = "1"
        android:background="@drawable/icon_bar_medias"
        android:contentDescription="@string/footer_img_media" />

    <ImageButton
        android:id="@id/mFooterHomeImg"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
       android:layout_weight = "1"
        android:background="@drawable/icon_bar_home"
        android:contentDescription="@string/footer_img_home" />

<LinearLayout/>

希望这对您有所帮助