Android - LinearLayout childs 像 StaggeredGridView 一样处理
Android - LinearLayout childs dispose like StaggeredGridView
我在 LinearLayout 中有 4 个元素(图像),我想像 StaggeredGridView 一样处理它们。
我可以用 LinearLayout 做到这一点吗?还有其他方法吗?
图片是动态添加的
您是否考虑将 RecyclerView
与 StaggeredGridLayoutManager
一起使用?
一个例子:here
如果您总是最多拥有 4 个项目,那么您可以这样做:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="" />
</LinearLayout>
</LinearLayout>
但我不推荐这个。我会选择 RecyclerView
,仅将它用于 4 个项目没有错。
我在 LinearLayout 中有 4 个元素(图像),我想像 StaggeredGridView 一样处理它们。 我可以用 LinearLayout 做到这一点吗?还有其他方法吗?
图片是动态添加的
您是否考虑将 RecyclerView
与 StaggeredGridLayoutManager
一起使用?
一个例子:here
如果您总是最多拥有 4 个项目,那么您可以这样做:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="" />
</LinearLayout>
</LinearLayout>
但我不推荐这个。我会选择 RecyclerView
,仅将它用于 4 个项目没有错。