的ImageButton:强制方形图标(?HEIGHT = WRAP_CONTENT,宽=) [英] ImageButton: Force square icon (height = WRAP_CONTENT, width = ?)
问题描述
在我的水平的LinearLayout我有一个文本编辑和ImageButton的。该ImageButton的是一样高的文本编辑。
In my horizontal LinearLayout I have a TextEdit and an ImageButton. The ImageButton is as high as the TextEdit.
我想,该ImageButton的是完全一样宽,它的长。
I'd like that the ImageButton is exactly as wide as it's long.
目前,它看起来像的ImageButton的宽度时,没有脱屑(ImageButton的宽度[像素] =未缩放宽度绘制[PX]),如:
At the moment it looks like the width of the ImageButton is like when there is no scaling (ImageButton width [px] = unscaled drawable width [px]):
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="@+id/txtName"
android:layout_width="1dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<ImageButton
android:id="@+id/btSet"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:scaleType="fitEnd"
android:src="@drawable/pin2" />
</LinearLayout>
应该如何看待这样的:
How it should look like:
推荐答案
试试这个,我觉得这应该工作:
Try this, I think this should work:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:orientation="horizontal" >
<ImageButton
android:id="@+id/btSet"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:scaleType="centerInside"
android:adjustViewBounds="true"
android:src="@drawable/pin2" />
<EditText
android:id="@+id/txtName"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toLeftOf="@id/btSet" />
</RelativeLayout>
释解: centerInside
将确保图像将的范围内按比例缩放的ImageButton
。 adjustViewBounds =真正的
将...好,调整视图的边界,如果需要的图像缩放。
Explaination: centerInside
will assure that the image will scale proportionally within the bounds of the ImageButton
. adjustViewBounds="true"
will...well, adjust the view's bounds, if the image needed to be scaled.
这篇关于的ImageButton:强制方形图标(?HEIGHT = WRAP_CONTENT,宽=)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!