android 2016新控件,Android其它新控件

本文介绍了Android中的两种常用新控件——DrawerLayout和SwipeRefreshLayout。DrawerLayout用于实现抽屉效果,通常包含主界面和抽屉视图,通过 Gravity.START 属性控制抽屉的开关。SwipeRefreshLayout则提供了下拉刷新的功能,用户可通过垂直滑动手势刷新内容。在Java代码中,可以调用相应方法来控制抽屉的开闭和刷新状态。
摘要由CSDN通过智能技术生成

Android其它新控件

欢迎转载,转载请注明原文出处:http://blog.csdn.net/lavor_zl/article/details/51312715,谢谢。

Android其它新控件是指非Android大版本更新时提出的新控件,也非谷歌IO大会提出的新控件,而是谷歌发现市场上某种功能的控件被大量使用,而不定期推出实现该功能的官方控件。Android其它新控件常用的有下面两种。

d154bc447236

1. Drawerlayout(抽屉布局)

抽屉布局的使用比较简单,一般在DrawerLayout下面定义两个视图,第一个视图作为主界面,第二个视图作为抽屉,注意第二个视图要设置android:layout_gravity属性,否则不会作为抽屉,而且我们打开关闭抽屉还和此属性相关。

在xml中定义DrawerLayout

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"

android:id="@+id/drawer_layout"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".MainActivity">

android:id="@+id/refresh"

android:layout_width="match_parent"

android:layout_height="match_parent">

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="sads" />

android:layout_gravity="start"

android:layout_width="match_parent"

android:layout_height="match_parent"

>

android:ems="1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="我是抽屉布局的抽屉部分" />

在java文件中怎么打开,关闭抽屉

//打开Gravity.START位置的抽屉

drawerlayout.openDrawer(Gravity.START);

//关闭Gravity.START位置的抽屉

drawerlayout.closeDrawer(Gravity.START);

抽屉关闭状态时:

d154bc447236

抽屉打开状态时:

d154bc447236

2. SwipeRefreshLayout(滑动刷新布局)

SwipeRefreshLayout使用户可以通过垂直滑动手势刷新视图的内容。

在xml中定义SwipeRefreshLayout

android:id="@+id/refresh"

android:layout_width="match_parent"

android:layout_height="match_parent">

android:gravity="center"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="我是主界面部分" />

在java中操作SwipeRefreshLayout

this.refresh = (SwipeRefreshLayout) findViewById(R.id.refresh);

refresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

@Override

public void onRefresh() {

Log.i("SwipeRefreshLayout","下拉刷新");

//do something,刷新视图内容

refresh.setRefreshing(false);//设置刷新结束

Log.i("SwipeRefreshLayout","刷新完毕");

}

});

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值