Android UI - 水平绘制多个 ImageView 使用什么 Layout
Android UI - What Layout to be used to draw many ImageView horizontally
我有一些图片,比如说 4 到 10 张图片。
我希望它们水平绘制并在添加更多图像时动态调整大小。
例如在下面的脚本中,我有 4 张图片。但是第四张图片没有绘制(只有 3 张图片可见):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:orientation="vertical"
android:gravity="center">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ball_1"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ball_1a"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ball_1b"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ball_1c"
/>
</LinearLayout>
</LinearLayout>
设计截图:
有什么解决办法吗?
提前致谢
你可以使用横向RecyclerView
设置方法如下:
LinearLayoutManager layoutManager
= new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
recyclerView.setLayoutManager(layoutManager);
检查这个例子:
我有一些图片,比如说 4 到 10 张图片。
我希望它们水平绘制并在添加更多图像时动态调整大小。
例如在下面的脚本中,我有 4 张图片。但是第四张图片没有绘制(只有 3 张图片可见):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:orientation="vertical"
android:gravity="center">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ball_1"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ball_1a"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ball_1b"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ball_1c"
/>
</LinearLayout>
</LinearLayout>
设计截图:
有什么解决办法吗?
提前致谢
你可以使用横向RecyclerView
设置方法如下:
LinearLayoutManager layoutManager
= new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
recyclerView.setLayoutManager(layoutManager);
检查这个例子: