Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/185.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android:ImageView重叠_Java_Android_Imageview_Android Relativelayout_Overlapping - Fatal编程技术网

Java Android:ImageView重叠

Java Android:ImageView重叠,java,android,imageview,android-relativelayout,overlapping,Java,Android,Imageview,Android Relativelayout,Overlapping,我有五个ImageView(ImageButtons),我想在一行上显示它,但是当我在一个小设备上时,我的最后一个图像被裁剪了 我怎么能修好它 有没有办法检测屏幕宽度 |A | B | C | D | E| 在我的RelativeLayout xml文件中: <ImageButton android:id="@+id/mFooterProfileImg" android:layout_width="wrap_content" android:

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

我怎么能修好它

有没有办法检测屏幕宽度

|A | B | C | 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" />

我认为正确的方法是创建线性布局, 确保方向是水平的。 然后将布局_width=“0dp”传递给每个图像按钮, 并为每个imageButton分配布局_weight=“20”

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


正如德尔戈勒姆所说。

我将德尔戈勒姆的评论作为回答,只是为了帮助你。在xml中使用以下代码来实现您的目标:

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


希望这对您有所帮助

您可以使用线性布局并利用权重来均匀细分屏幕(20%、20%、20%、20%和20%)。还要注意的是,对于每个屏幕密度,
应该有不同的可绘制文件夹,每个文件夹都包含一个预缩放的图像集。或者,以支持的最大密度(适当缩放)提供图像,并让Android进行缩放。是的。但您也可以为权重指定0.2的值(这是直观的)。或者全部为1(好吧,android会正确地将权重和计算为5,并说“每一个都需要1/5”)+1.