警报文本很长时,不显示布局视图

时间:2014-08-18 20:59:55

标签: android android-layout android-alertdialog

在选项菜单中,有一个专门关于应用程序的作者。它显示了一些描述文本,我添加了一个带有两个按钮的图片的布局,一个用于关闭对话框,另一个用于发送邮件。这是代码:

public void autorVitals(){

    String mensaje = getString(R.string.descripcionAutor);
    //mensaje = mensaje + mensaje;
    //mensaje = mensaje + mensaje + mensaje;

        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);

        LayoutInflater factory = LayoutInflater.from(this);
        final View aut_view = factory.inflate(R.layout.author, null);

        Button buttonclosedial  = (Button) view.findViewById(R.id.botonok);

        // set title
        alertDialogBuilder.setTitle(getString(R.string.tituloDescAut));

        // set dialog message
        alertDialogBuilder
            .setView(aut_view)
            .setMessage(mensaje);

            // create alert dialog
            final AlertDialog alertDialog = alertDialogBuilder.create();
            // show it
            alertDialog.show();
            botoncerrardial.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View view) {
                    //Toast.makeText(MainActivity.this, "Button Clicked",   Toast.LENGTH_SHORT).show();
                    alertDialog.dismiss();
                }
            });
}

对于平板电脑,此菜单看起来很完美。但我已经意识到,对于屏幕较小的设备,如果向下滚动到结束行但是看不到aut_view,则只显示mensaje的文本。阅读是stackoverflow一些人设置一些属性到布局,如填充父,添加滚动视图等。我已经使用它们所有没有期望的结果。现在,我也意识到如果我将文本缩短,布局可以部分看到,也可以单独滚动文本。如何以优雅的方式为用户提供良好的视图?我认为最好的解决方案是完全放在一起,文字,图片和按钮在一个布局中,你不觉得吗?。

1 个答案:

答案 0 :(得分:0)

试试这个..

// you put this line after alertdialog
ScrollView scrolview = new ScrollView(this);
//put this line before alertdialog.create.show()
scrolview.addview(aut_view); // so you create a scrollview as the root view, and add the inflated view..

所以基本上你的所有视图都将被放入滚动布局..