Android之旅第五站——ListView对话框dialog …

实现ListView做的对话框dialog。

看效果图:

这里写图片描述

这里用ArrayAdapter简单点作了adapter填充内容。当然,你想用哪个adapter都可以,simpleadapter,自定义adapter等。

先附上代码:

Mainactivity:

package com.example.dialog1;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Toast;

public class 
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Android应用开发过程中,有时候我们需要实现全屏滚动的效果,或者在滚动页面中嵌入ListView等组件。下面就来介绍一下如何实现这些效果。 一、全屏滚动 实现全屏滚动需要用到Android系统提供的ScrollView组件。ScrollView可以包含多个子视图,并且可以在垂直方向上进行滚动。下面是一个简单的例子: ``` <ScrollView android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="这是第一行"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="这是第二行"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="这是第三行"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="这是第四行"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="这是第五行"/> </LinearLayout> </ScrollView> ``` 上面的代码中,我们将ScrollView作为根布局,然后在ScrollView内部添加了一个垂直方向的LinearLayout,这个LinearLayout包含了多个TextView,每个TextView显示一行文本。运行这个应用,可以看到整个页面可以在垂直方向上滚动。 二、在滚动页面中嵌入ListView 有时候我们需要在滚动页面中嵌入ListView,这时候可以使用Android系统提供的NestedScrollView组件。NestedScrollView是ScrollView的子类,可以包含多个子视图,并且可以在垂直方向上进行滚动。和ScrollView不同的是,NestedScrollView可以嵌套其他可滚动的组件,例如ListView等。 下面是一个简单的例子: ``` <android.support.v4.widget.NestedScrollView android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="这是第一行"/> <ListView android:layout_width="match_parent" android:layout_height="wrap_content" android:divider="@null" android:dividerHeight="0dp" android:scrollbars="none"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="这是第三行"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="这是第四行"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="这是第五行"/> </LinearLayout> </android.support.v4.widget.NestedScrollView> ``` 上面的代码中,我们将NestedScrollView作为根布局,然后在NestedScrollView内部添加了一个垂直方向的LinearLayout。这个LinearLayout包含了多个TextView和一个ListView。由于ListView也可以滚动,所以我们需要将它的滚动条隐藏掉,然后就可以在滚动页面中嵌入ListView了。 以上就是Android开发中如何实现全屏滚动和在滚动页面中嵌入ListView的方法。希望对你有所帮助。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值