我有一个内置的 Android 应用程序,其中我有 3 ImageView
s 水平放置在 a 上LinearLayout
,它们被放置在 aandroid:layout_width="0dp"
和android:layout_weight="1"
这样它们在布局中均匀分布。
现在我必须切换到使用 a RelativeLayout
(因为我想重叠另一个图像并且不能用 a 来完成LinearLayout
)所以我想开始复制相同的效果,让 3 ImageView
s 在父布局中均匀分布/缩放,但我不确定如何实现这一目标。
我觉得我需要利用android:scaleType
......也许是中心作物:
均匀缩放图像(保持图像的纵横比),使图像的两个尺寸(宽度和高度)都等于或大于视图的相应尺寸(减去填充)。
这听起来不错,但我似乎无法让它正常工作......关于如何实现ImageView
s 在我RelativeLayout
的 s 中的均匀分布有什么想法吗?
现在的代码片段:
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal" >
<ImageView
android:id="@+id/dragcircle"
android:layout_width="wrap_content"
android:tag="circle"
android:layout_alignParentLeft="true"
android:layout_height="wrap_content"
android:adjustViewBounds="false"
android:scaleType="centerCrop"
android:src="@drawable/circle" />
<ImageView
android:id="@+id/dragsquare"
android:layout_width="wrap_content"
android:tag="square"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/dragcircle"
android:adjustViewBounds="false"
android:src="@drawable/square" />
<ImageView
android:id="@+id/dragtriangle"
android:layout_width="wrap_content"
android:tag="triangle"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/dragsquare"
android:adjustViewBounds="false"
android:src="@drawable/triangle" />
注意:我在 SO 上找不到与此问题具有相同约束的问题。有很多问题,例如:
Android:RelativeLayout 内的组件空间如何均匀? 和 android的RelativeLayout,等间距?
但是,如果您查看详细信息,您会发现他们没有考虑将其LinearLayout
作为等间距的选项,并且切换布局类型最终成为解决方案。我有,我正在使用它,但它对我不起作用,因为我需要重叠图像:
注意这个例子,我有 3 个ImageView
基本形状,但我也有一个 4个 ImageView
(它开始隐藏),它与中间的重叠。这就是为什么我必须使用RelativeLayout