Android其它新控件

Android其它新控件


欢迎转载,转载请注明原文出处:http://blog.csdn.net/lavor_zl/article/details/51312715,谢谢。
Android其它新控件是指非Android大版本更新时提出的新控件,也非谷歌IO大会提出的新控件,而是谷歌发现市场上某种功能的控件被大量使用,而不定期推出实现该功能的官方控件。Android其它新控件常用的有下面两种。

1. Drawerlayout(抽屉布局)


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

在xml中定义DrawerLayout


<android.support.v4.widget.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.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/refresh"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="sads" />
    </android.support.v4.widget.SwipeRefreshLayout>

    <LinearLayout
        android:layout_gravity="start"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        >
        <TextView
            android:ems="1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="我是抽屉布局的抽屉部分" />
    </LinearLayout>
</android.support.v4.widget.DrawerLayout>  

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


        //打开Gravity.START位置的抽屉
        drawerlayout.openDrawer(Gravity.START);
        //关闭Gravity.START位置的抽屉
        drawerlayout.closeDrawer(Gravity.START);  

抽屉关闭状态时:

抽屉打开状态时:

2. SwipeRefreshLayout(滑动刷新布局)


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

在xml中定义SwipeRefreshLayout


 <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/refresh"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:gravity="center"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="我是主界面部分" />
 </android.support.v4.widget.SwipeRefreshLayout>  

在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","刷新完毕");
            }
        });  

本程序源代码下载:Android其它新控件

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 179,665评论 25 708
  • 内容抽屉菜单ListViewWebViewSwitchButton按钮点赞按钮进度条TabLayout图标下拉刷新...
    皇小弟阅读 47,218评论 22 665
  • Android UI相关开源项目库汇总OpenDigg 抽屉菜单MaterialDrawer ★7337 - 安卓...
    黄海佳阅读 8,843评论 3 77
  • “别动我,我在想个名字” “什么名字” “简文的名字” “我想起个特别牛B的名字” “那就叫牛B” “牛B……”我...
    会飞的香猪阅读 167评论 0 2
  • 一叶一阳光.一叶一诗意.一片片飘落;一叶叶枯萎;天空.依然湛蓝.而你却不再那样绿。在等待飘落的曰子里.你的心停在何...
    兰如纯阅读 97评论 0 0

友情链接更多精彩内容