zoukankan      html  css  js  c++  java
  • Android学习之——单击ActionBar实现ListView返回顶部

    不知道大家在刷微博时,有没有遇到过,刷新太多,想返回顶部看之前的微博的情况。其实,单击顶部的ActionBar能返回顶部。而不用一直向下拉。

    废话不多说,讲讲Android中怎么实现这一功能。

    首先,要给ActionBar添加一个CustomView。

    CustomView的布局文件actionbar_layout.xml:

     1 <?xml version="1.0" encoding="utf-8"?>
     2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     3     android:id="@+id/ll_topbar"
     4     android:layout_width="match_parent"
     5     android:layout_height="wrap_content"
     6     android:orientation="vertical" >
     7 
     8     <TextView
     9         android:layout_width="wrap_content"
    10         android:layout_height="wrap_content"
    11         android:layout_gravity="center"
    12         android:textColor="#000000"
    13         android:id="@+id/mytext"
    14         android:textSize="18sp" />
    15 
    16 </LinearLayout>

    然后设置ActionBar或者加载CustiomView都可以

    1 ActionBar actionBar = getActionBar();
    2 actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
    3 actionBar.setCustomView(R.layout.actionbar_layout);
    1   View customView = LayoutInflater.from(this).inflate(R.layout.actionbar_layout, new LinearLayout(this), false);
    2   getActionBar().setDisplayShowCustomEnabled(true); 
    3   getActionBar().setCustomView(customView);

    最后给CustiomView添加OnClick事件实现ListView返回顶部逻辑即可:

    1   if (!mListView.isStackFromBottom()) {
    2           mListView.setStackFromBottom(true);
    3   }
    4     mListView.setStackFromBottom(false);


    http://www.tuicool.com/articles/6jEVze3
  • 相关阅读:
    批处理 windows service 的安装与删除
    HTML 页面元素介绍
    六 redis学习笔记之发布订阅
    发布个c#版的HandlerSocket客户端类库
    数据库单元测试
    一 redis学习笔记之环境搭建
    七 redis学习笔记之持久化
    三 redis学习笔记之排序
    四 redis学习笔记之事务
    元数据编程实战_使用Emit运行时生成Protobuf编码类
  • 原文地址:https://www.cnblogs.com/manmanlu/p/4322859.html
Copyright © 2011-2022 走看看