Java 在布局中组合2个图像视图
我想在一个布局中组合两个任意宽度和相同高度的图像(填充设备的宽度) 此示例包括:Java 在布局中组合2个图像视图,java,android,android-layout,Java,Android,Android Layout,我想在一个布局中组合两个任意宽度和相同高度的图像(填充设备的宽度) 此示例包括: 骰子:427x427 多米诺骨牌:900x427 给定一张多米诺骨牌图像和另一张骰子图像,目标可能是: 我的初始代码是: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layou
- 骰子:427x427
- 多米诺骨牌:900x427
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#999999"
android:orientation="horizontal" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="@drawable/domino" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="@drawable/dice" />
</LinearLayout>
对于xlarge屏幕,结果是:
对于较小的屏幕,多米诺骨牌占据所有宽度,骰子甚至不会出现
还尝试将两幅图像的权重设置为1,但结果也是错误的,并且根据屏幕大小而不同
我怎样才能解决这个问题?谢谢 查看这是否是您想要的布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#999999" >
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="@drawable/dice" />
<ImageView
android:id="@id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/imageView2"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@id/imageView2"
android:src="@drawable/domino" />
</RelativeLayout>
您可能需要
图像视图的android:scaleType
属性来“拉伸”图像。您可以尝试将骰子的权重设置为427,domino的权重设置为900。尝试过了,使用该配置,两个图像的宽度相同(每个屏幕的一半)嗨,只是一个建议,在您的情况下,如果使用“权重”属性,则必须将宽度设置为0,否则权重无效。您是否将其设置为0?它对布局大小很有效,但我还需要保持纵横比=(@Addev来自imageview
的图像的纵横比?您是否尝试使用scaleType
属性(如果我没有弄错的话,将fitXY
作为值)?