好了,我要设置一个图像如下:
-
图像的底部与布局的中心对齐
-
图像缩放与布局,以适应背景图像
我所做的是:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="2"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1">
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.9"/>
<ImageView
android:id="@+id/widget_icon"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:layout_weight="0.1"
android:src="@drawable/widget_icon"/>
</LinearLayout>
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
所以我希望图像占用窗口上半部分空间的10%,无论窗口高度/宽度设置为什么,但我已经意识到情况并非如此。看起来图像没有缩小到它的"真实"尺寸?我不完全确定,但我得到一些真的不稳定,似乎不是线性缩放发生,当它涉及到widget_icon。这是已知问题还是我在这里做错了什么?
您应该查看ImageView ScaleTypes
看起来你可能也不明白重量是如何工作的
通常将宽度或高度设置为0dp,然后设置粗细。如果你有两个项目,你将权重设置为1,它们都将占据各自宽度或高度的一半。如果你将一个设置为1,另一个设置为2,那么设置为2的将占用布局宽度或高度的2/3,设置为1的将占用布局宽度或高度的1/3
希望能有所帮助