对话框中的分隔线 [英] Divider line in dialog

查看:136
本文介绍了对话框中的分隔线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到Google应用程序中有一些非常有用的东西。

I noticed something very useful in Google apps.

当我们有内容丰富的对话框时,显示分隔线是为了强调滚动能力,如以下两幅图所示:

When we have dialog with big content, divider line is showing in order to emphasize ability to scroll, like in this two pictures:

但是,我不知道如何实现

But, I have no idea how to implement such behaviour using known utils.

最好的例子是在选择电话铃声时,开始时底部只有分隔线,但是当我们开始滚动时会出现两个分隔线。

Best example is while choosing phone ring, at the start there is only divider on the bottom, but when we start scrolling two dividers appear.

问题

如何实现di中出现和消失的行为

How to implement appearing and disappearing behaviour in dialog?

推荐答案

您想要实现的行为来自带有可滚动内容的对话框。请阅读本文档以了解其内容。

The behaviour that you want to achieve comes with a Dialog with Scrollable Content. Please read this document to get an idea of that.

在这种情况下,您需要使用 ListView 和几个按钮来创建自己的自定义布局xml。并且您需要将整个布局保留在 ScrollView 下。

In this case, you need to create your own custom layout xml with ListView and couple of buttons. And you need to keep this entire layout under ScrollView.

以下只是一个虚拟代码,可以帮助您:

The following is just a dummy code to help you with:

使用实际代码编辑伪代码:

布局。 xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_width="match_parent">

<ListView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/ListView"/>

</LinearLayout>

MainActivity.class:

MainActivity.class:

 LayoutInflater inflater= LayoutInflater.from(this);
    view=inflater.inflate(R.layout.layout, null);
    ListView listView = (ListView)view.findViewById(R.id.ListView);
    String[] items = { "Milk", "Butter", "Yogurt", "Toothpaste", "Ice Cream" };
    ArrayAdapter adapter_dest = new ArrayAdapter(this,android.R.layout.simple_list_item_1,items);
    listView.setAdapter(adapter_dest);
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Custom Dialog")
            .setCancelable(false)
            .setView(view)
            .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            });
    AlertDialog alert = builder.create();
    alert.show();

希望这会有所帮助!

这篇关于对话框中的分隔线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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