【发布时间】:2017-02-03 06:45:34
【问题描述】:
我正在尝试使用 LinearLayout 来实现具有多个图像的布局,这些图像的水平位置均匀分布在某个宽度 [A] 的容器中。随着容器宽度的缩小,图像应该会相互重叠。
<LinearLayout
android:orientation="horizontal"
android:layout_width="128dp" <--- [A]
android:layout_height="64dp"
>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
>
<ImageView
android:layout_width="wrap_content" <---- [B]
android:layout_height="wrap_content"
android:layout_centerInParent="true"
app:srcCompat="@drawable/ic_star_black_24dp"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
app:srcCompat="@drawable/ic_star_black_24dp"
/>
</RelativeLayout>
</LinearLayout>
上面的布局将图片均匀分布在容器宽度[A]中:
但是,当将 [A] 更改为应该使图像重叠的某个小值时,它们会按比例缩小以使其适合其父级 RelativeLayout 的宽度。这很奇怪,因为我在 [B] 处明确询问了 wrap_content 的宽度。我不希望图像被缩放。
有什么想法可以让我完成这项工作吗?
(我希望图像重叠的原因是因为它是过渡期间预期编排的一部分。它们的最终位置将是不重叠的。)
【问题讨论】:
-
如果你分享它的图像/草图会更好理解
-
没什么花哨的,只是旁边的几颗星星,就像★★★★★。上面的例子只显示了两个。我希望星星最初折叠成一颗星星(即五颗星星相互重叠),然后过渡将它们分开。
-
@digorydoo 那么你必须使用动画
-
一旦布局按预期工作,我会的。这个想法是动画基本上改变了父LinearLayout的layout_width。
标签: android android-layout android-linearlayout android-relativelayout overlapping