是否可以向滚动视图添加按钮?
我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是任何 Android 用户都想做的。无论如何,如果您想提供“通过按钮关闭”功能,请记住这一点:ScrollView 不能包含多个项目,因此您必须将
TextView
和 Button 都包装在中LinearLayout
之类的。但是,我的建议是您应该构建一个
AlertDialog
,它可以自动配置一个“确定”按钮,该按钮将关闭对话框。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 aLinearLayout
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.