You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android Studio实现双图片分屏填充屏幕的方法求助

实现双图左右分屏填充屏幕的布局修改方案

你的当前布局使用了**垂直方向(vertical)**的LinearLayout,还额外添加了空View,这只能展示单张图片。要实现左右各占一半的分屏效果,只需调整布局方向并添加第二个ImageView即可,具体修改如下:

修改后的完整布局代码

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/ImageView_left"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:scaleType="centerCrop"
        android:src="@drawable/img_left" />

    <ImageView
        android:id="@+id/ImageView_right"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:scaleType="centerCrop"
        android:src="@drawable/img_right" />

</LinearLayout>

关键修改点说明

  • 将外层LinearLayout的android:orientation从vertical改为horizontal,让子View横向排列
  • 移除多余的RelativeLayout和空View,直接在LinearLayout中放置两个ImageView
  • 给每个ImageView设置android:layout_width="0dp" + android:layout_weight="1",确保两个View平均分配屏幕宽度
  • 添加android:scaleType="centerCrop"(也可根据需求替换为fitXY等),保证图片填满所在区域,避免拉伸变形

如果需要给图片添加点击事件或嵌套其他布局,也可以把每个ImageView放在单独的RelativeLayout/FrameLayout中,再给容器设置相同的layout_weight,核心逻辑保持不变。

内容的提问来源于stack exchange,提问作者user18919576

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 07:39:21