Android-如何使此警报对话框可滚动? [英] Android - How do i make this alert dialog scrollable?

查看:81
本文介绍了Android-如何使此警报对话框可滚动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是android的初学者,并且制作了我的第一个android应用.我的关于"菜单项在单击时会显示一条警告对话框,其中包含很长的消息. 我一直在尝试不同的方法来使其可滚动,但是我做不到.我尝试阅读有关stackoverflow的其他问题,但它们对我没有用.这是我的警报对话框代码.

I am beginner in android and making my first android app. my 'About' menu item, when clicked shows an alertdialog with a really long message. I have been trying different methods to make it scrollable but i couldn't. I have tried reading different questions on stackoverflow but they didn't worked for me. Here is my alert dialog code.

AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);  
alertDialog.setTitle("Title");  
alertDialog.setMessage("Here is a really long message.");  
 alertDialog.setButton("OK", null);  
 AlertDialog alert = alertDialog.create();
alert.show();

有人能详细解释一下如何使其滚动吗? 任何帮助或建议,将不胜感激!

Can anybody explain me in detail that how to make it scrollable? Any help or suggestions would be appreciated !

推荐答案

此解决方案来自为了使视图可滚动,它必须嵌套在ScrollView容器内:

In order for a view to scrollable, it must be nested inside of a ScrollView container:

<ScrollView>
    <LinearLayout android:orientation="vertical"
            android:scrollbars="vertical"
            android:scrollbarAlwaysDrawVerticalTrack="true">
        <TextView />
        <Button />
    </LinearLayout>
</ScrollView>

请注意,一个ScrollView容器只能具有一个子布局视图.例如,不可能在没有LinearLayout的情况下将TextView和Button放置在ScrollView中.

Note that a ScrollView container can only have one child layout view. It is not possible, for example, to place a TextView and Button in a ScrollView without the LinearLayout.

这篇关于Android-如何使此警报对话框可滚动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆