(android)当屏幕宽度已满时,如何将继续的图像放在下一行?
(android) How to put images that continue on next line when screen width is full?
嗯...也许这很简单,但我找不到如何执行此操作的示例。
我需要显示一组图像按钮(将近 10 个),我希望使用可用宽度在另一个图像按钮的右侧显示一次,当没有更多空间时,然后在 space 以下。 (在 html 中非常简单,我在 android 中要疯了)
最初的想法是图像和下面的文本视图作为标题,后来我发现它对我最基本的东西来说太多了Android,所以我决定,只有图像按钮。
将固定数量作为参数并调整图像大小以适应屏幕分布非常可爱....这对我现在来说也太多了。
我考虑了这个想法...相对布局假设当没有更多 space 可用时,它会在下面继续...我不能。
作为水平线形布局....我不能:(
我应该从代码而不是布局来做到这一点吗?
这是我的实际屏幕:
http://imgur.com/a11LFEs
这是我的基本代码:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageButton1"
android:src="@drawable/btn_fra_pierre"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageButton2"
android:src="@drawable/btn_sab_evo"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/imageButton1"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageButton3"
android:src="@drawable/btn_fra_pierre"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/imageButton2"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageButton4"
android:src="@drawable/btn_sab_evo"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/imageButton3"/>
</RelativeLayout>
非常感谢!
您尝试做的是 FlowLayout。它在标准 android SDK 中不可用。您可能必须为此编写自己的自定义布局。我建议看看一些第三方库,例如 https://github.com/ApmeM/android-flowlayout
Google 的 flexbox-layout 有点新:https://github.com/google/flexbox-layout
嗯...也许这很简单,但我找不到如何执行此操作的示例。
我需要显示一组图像按钮(将近 10 个),我希望使用可用宽度在另一个图像按钮的右侧显示一次,当没有更多空间时,然后在 space 以下。 (在 html 中非常简单,我在 android 中要疯了)
最初的想法是图像和下面的文本视图作为标题,后来我发现它对我最基本的东西来说太多了Android,所以我决定,只有图像按钮。
将固定数量作为参数并调整图像大小以适应屏幕分布非常可爱....这对我现在来说也太多了。
我考虑了这个想法...相对布局假设当没有更多 space 可用时,它会在下面继续...我不能。
作为水平线形布局....我不能:(
我应该从代码而不是布局来做到这一点吗?
这是我的实际屏幕: http://imgur.com/a11LFEs
这是我的基本代码:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageButton1"
android:src="@drawable/btn_fra_pierre"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageButton2"
android:src="@drawable/btn_sab_evo"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/imageButton1"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageButton3"
android:src="@drawable/btn_fra_pierre"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/imageButton2"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageButton4"
android:src="@drawable/btn_sab_evo"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/imageButton3"/>
</RelativeLayout>
非常感谢!
您尝试做的是 FlowLayout。它在标准 android SDK 中不可用。您可能必须为此编写自己的自定义布局。我建议看看一些第三方库,例如 https://github.com/ApmeM/android-flowlayout
Google 的 flexbox-layout 有点新:https://github.com/google/flexbox-layout