【发布时间】:2011-12-19 04:48:54
【问题描述】:
可能重复:
how do i keep the aspect ratio on image buttons in android?
我有 5 个方形骰子作为图像按钮,排列在布局底部附近。我希望它们占据布局的整个宽度,但我似乎无法让它们在占据整个宽度的同时正确保持该纵横比。 目前我的代码如下所示:
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="60dp"
android:layout_margin="1dp"
android:layout_gravity="bottom"
>
<ImageButton
android:id="@+id/die1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:adjustViewBounds="true"
android:layout_weight="1"
android:layout_margin="2dp"
android:scaleType="centerInside"
/>
<ImageButton
android:id="@+id/die2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:adjustViewBounds="true"
android:layout_weight="1"
android:layout_margin="2dp"
android:scaleType="centerInside"
/> .....
看起来像这样:
如果我不包括
android:layout_height="60dp"
然后骰子会倾斜,看起来像这样:
但是,当我尝试在平板设备或高分辨率的设备上显示时,会出现保留“60dp”部分的问题,它最终看起来像这样:
我哪里错了?!
【问题讨论】:
-
试试
android:layout_height="wrap_content" -
这就是给我这个的原因:i.stack.imgur.com/yT5WX.jpg
-
申请线性布局高度
-
我不确定你的意思?当我用 android:layout_height="wrap_content" 替换 android:layout_height="60dp" 时,它看起来像上图。
-
现在
<LinearLayout>属性是android:layout_height="60dp"替换为android:layout_height="wrap_content"
标签: android aspect-ratio