我无法获得已缩小到我的应用程序中心的ImageView。我试过不同的scaleTypes(fitCenter,centerInside都给出了正确的尺寸,但都不居中),我试过使用RelativeLayout而不是LinearLayout,我尝试添加0.25的重量空视图到任何一方,我已经尝试将layout_width设置为特定的宽度,而不是使用layout_weight ...没有任何东西显示出来,图像只是左对齐。思考?居中缩放的ImageView
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:weightSum="1">
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:layout_gravity="center"
android:src="@drawable/logo"
android:adjustViewBounds="true"
android:scaleType="centerInside" />
</LinearLayout>
重量是我如何缩放图像。这里的意图是图像占用宽度的50%。我尝试在图像周围放置空洞的视图,每个图像的重量为0.25,以尝试“填充”周围空间并将其强制到中间,但这也不起作用。 – Deeko
我得到了空的意见工作(见编辑);我必须指定'0dp'的高度和宽度,并且我必须确保我的父级LinearLayout具有'orientation =“horizontal”'。 –
啊!你是对的,它为空白视图添加了0dp高度。我的宽度为0dp,高度为match_parent。谢谢! – Deeko