在我的水平LinearLayout中,我有一个TextEdit和一个
ImageButton.
ImageButton与TextEdit一样高.
我希望ImageButton的长度和它一样宽.
目前看起来ImageButton的宽度就像没有缩放时一样(ImageButton width [px] =未缩放的可绘制宽度[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>
它应该如何:
解决方法
试试这个,我认为这应该有效:
- <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 =“true”将…好吧,调整视图的边界,如果图像需要缩放.