是否可以向滚动视图添加按钮?

发布于 2024-10-04 09:34:10 字数 726 浏览 1 评论 0原文

我在 layout 中有一个简单的 ScrollView,它以对话框格式显示 About Box。所以它只是在对话框中弹出在手机屏幕上。用户关闭该框的唯一方法是单击后退按钮(这是一个意图)。

我是否有办法向该框添加关闭按钮,或者我可以让用户用手指点击屏幕上的框并将其关闭吗?

这是我的 xml

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:screenOrientation="portrait"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="10dip" >

   <TextView
       android:id="@+id/about_box"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="@string/about_text" />
</ScrollView>

I have a simple ScrollView in a layout that displays an About Box in a dialog format. So it just pops up on the phone screen in a dialog. The only way for the user to close the box is to click the back button (it is an intent).

Do I have a way of adding a close button to the box or could I have the user hit the box on the screen with their finger and close it?

Here is my xml:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:screenOrientation="portrait"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="10dip" >

   <TextView
       android:id="@+id/about_box"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="@string/about_text" />
</ScrollView>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萌吟 2024-10-11 09:34:10

<块引用>

用户关闭该框的唯一方法是单击后退按钮

这是任何 Android 用户都想做的。无论如何,如果您想提供“通过按钮关闭”功能,请记住这一点:ScrollView 不能包含多个项目,因此您必须将 TextView 和 Button 都包装在 中LinearLayout之类的。

但是,我的建议是您应该构建一个 AlertDialog,它可以自动配置一个“确定”按钮,该按钮将关闭对话框。

The only way for the user to close the box is to click the back button

That's what any Android user would want to do. Anyway, if you want to provide the "close with button" functionality just keep in mind this: ScrollView cannot contain more than one item, so you will have to wrap both TextView and Button inside a LinearLayout or something.

But, my suggestion is that you should build an AlertDialog, which can be automatically configured with an "OK" button which will close the dialog.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文