gpt4 book ai didi

android - 什么 Android 布局允许包装 block /按钮 - 而不是奇怪的拉伸(stretch)?

转载 作者:行者123 更新时间:2023-11-29 21:50:00 25 4
gpt4 key购买 nike

我想找到合适的布局来包裹按钮而不是奇怪的拉伸(stretch)。

一些例子是我得到的:

invalid wrap

我要实现的目标:

valid wrap

如果在 Android 中可能的话,请帮助解释一下在 HTML5 中很容易的事情 - 我正在考虑 ScrollView 但不确定是否需要它。我搜索了很多页面但没有找到好的解决方案,认为这很简单但不知道答案。

这是当前代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
tools:ignore="HardcodedText" />

<Button
android:id="@+id/btn_goHome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/button1"
android:text="@string/button_go_home" />

<Button
android:id="@+id/btn_openEmails"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/btn_goHome"
android:text="@string/button_open_emails" />

<Button
android:id="@+id/btn_openTests"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/btn_openEmails"
android:text="Open tests" />

<ScrollView
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/btn_openTests"
android:layout_centerHorizontal="true" >

<LinearLayout
android:id="@+id/list1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="?android:dividerHorizontal"
android:orientation="vertical"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:showDividers="middle" >

</LinearLayout>
</ScrollView>

</RelativeLayout>

最佳答案

我会推荐 FlowLayout 由他自己创建的 - Romain Guy。我认为它会完全满足您的要求。

这是实现:Android Layouts.zip

这是他的原始帖子:How can I do something like a FlowLayout in Android?

可在此处找到替代实现:FlowLayout in Android

最后,您在 GitHub 上有了一个使用 BSD 许可证的实现:ApmeM / android-flowlayout .有一些屏幕截图和文档可以帮助您快速上手。

关于android - 什么 Android 布局允许包装 block /按钮 - 而不是奇怪的拉伸(stretch)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14677097/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com