[英]Android : ImageView overlapping
我有五个ImageViews(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" />
我认为,这样做的正确方法是创建线性布局,并确保方向是水平的。 然后为每个imageButton传递layout_width =“ 0dp”,并为每个imageButton分配layout_weight =“ 20”
这为每张图片提供了20%的宽度。
就像Der Golem所说的那样。
我正在发布Der Golem的评论作为答案,只是为了帮助您。 在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/>
希望这对您有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.