欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android實(shí)現(xiàn)標(biāo)題顯示隱藏功能

 更新時(shí)間:2016年02月19日 11:36:35   作者:阿冰的學(xué)習(xí)日記  
這篇文章主要介紹了Android實(shí)現(xiàn)標(biāo)題顯示隱藏功能

本文實(shí)例嘗試模仿實(shí)現(xiàn)Android標(biāo)題顯示隱藏功能,通過給listview設(shè)置 mListView.setOnTouchListener 監(jiān)聽 重寫ontouch方法 監(jiān)聽手指一動的坐標(biāo),當(dāng)超過ViewConfiguration.get(this).getScaledTouchSlop(); toubar的高度 .當(dāng)向上滑動超過這個(gè)高度顯示touba 向下滑動隱藏。

效果圖:

package com.example.hidetitlebardemo;

import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.AbsListView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.SimpleAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MainActivity extends Activity {
 private ListView mListView;
 private RelativeLayout mTitle;
 private int mTouchSlop;
 private SimpleAdapter mAdapter;
 private float mFirstY;
 private float mCurrentY;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 requestWindowFeature(Window.FEATURE_NO_TITLE);
 setContentView(R.layout.activity_main);
 mTouchSlop = ViewConfiguration.get(this).getScaledTouchSlop();
 
 initViews();
 showHideTitleBar(true);
 
 }

 private void initViews() {
 mListView = (ListView) findViewById(R.id.id_lv);
 mTitle = (RelativeLayout) findViewById(R.id.id_title);

 mAdapter = new SimpleAdapter(this, getData(),
 R.layout.lv_item,
 new String[]{"info"},
 new int[]{R.id.num_info});
 mListView.setAdapter(mAdapter);
 mListView.setOnTouchListener(new View.OnTouchListener() {

 @Override
 public boolean onTouch(View v, MotionEvent event) {
 switch (event.getAction()) {
 case MotionEvent.ACTION_DOWN:
 mFirstY = event.getY();
 break;
 case MotionEvent.ACTION_MOVE:
 mCurrentY = event.getY();
 if (mCurrentY - mFirstY > mTouchSlop) {
 System.out.println("mtouchislop:" + mTouchSlop);
 // 下滑 顯示titleBar
 showHideTitleBar(true);
 } else if (mFirstY - mCurrentY > mTouchSlop) {
 // 上滑 隱藏titleBar
 showHideTitleBar(false);
 }
 break;
 case MotionEvent.ACTION_UP:
 break;
 }
 return false;
 }
 });
 }

 private Animator mAnimatorTitle;
 private Animator mAnimatorContent;

 private void showHideTitleBar(boolean tag) {
 if (mAnimatorTitle != null && mAnimatorTitle.isRunning()) {
 mAnimatorTitle.cancel();
 }
 if (mAnimatorContent != null && mAnimatorContent.isRunning()) {
 mAnimatorContent.cancel();
 }
 if (tag) {
 mAnimatorTitle = ObjectAnimator.ofFloat(mTitle, "translationY", mTitle.getTranslationY(), 0);
 mAnimatorContent = ObjectAnimator.ofFloat(mListView, "translationY", mListView.getTranslationY(), getResources().getDimension(R.dimen.title_height));

 } else {
 mAnimatorTitle = ObjectAnimator.ofFloat(mTitle, "translationY", mTitle.getTranslationY(), -mTitle.getHeight());
 mAnimatorContent = ObjectAnimator.ofFloat(mListView, "translationY", mListView.getTranslationY(),0);
 }
 mAnimatorTitle.start();
 mAnimatorContent.start();

 }


 private List<Map<String, Object>> getData() {
 List<Map<String, Object>> data = new ArrayList<>();
 for (int i = 'A'; i < 'z'; i++) {
 Map<String, Object> map = new HashMap<>();
 map.put("info", (char) i);
 data.add(map);
 }
 return data;
 }


}

布局

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:orientation="vertical"
 xmlns:android="http://schemas.android.com/apk/res/android">
 <RelativeLayout
 android:id="@+id/id_title"
 android:background="#00ccff"
 android:layout_width="match_parent"
 android:layout_height="40dp">
 <TextView
 android:text="Ace "
 android:layout_centerInParent="true"
 android:textSize="22sp"
 android:textColor="#ffffff"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content" />
 </RelativeLayout>
 <ListView
 android:id="@+id/id_lv"
 android:layout_width="match_parent"
 android:layout_height="match_parent"/>


</RelativeLayout>

希望本文所述對大家學(xué)習(xí)Android軟件編程有所幫助。

相關(guān)文章

  • Android編程開發(fā)錄音和播放錄音簡單示例

    Android編程開發(fā)錄音和播放錄音簡單示例

    這篇文章主要介紹了Android編程開發(fā)錄音和播放錄音的方法,結(jié)合實(shí)例形式分析了Android多媒體開發(fā)中音頻操作的相關(guān)技巧,需要的朋友可以參考下
    2016-08-08
  • Android實(shí)現(xiàn)注冊頁面

    Android實(shí)現(xiàn)注冊頁面

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)注冊頁面之監(jiān)聽器,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-04-04
  • Android內(nèi)置的OkHttp用法介紹

    Android內(nèi)置的OkHttp用法介紹

    okhttp是一個(gè)第三方類庫,用于android中請求網(wǎng)絡(luò)。這是一個(gè)開源項(xiàng)目,是安卓端最火熱的輕量級框架,由移動支付Square公司貢獻(xiàn)(該公司還貢獻(xiàn)了Picasso和LeakCanary) 。用于替代HttpUrlConnection和Apache HttpClient
    2022-08-08
  • Android控件BottomSheet實(shí)現(xiàn)底邊彈出選擇列表

    Android控件BottomSheet實(shí)現(xiàn)底邊彈出選擇列表

    這篇文章主要介紹了Android控件BottomSheet實(shí)現(xiàn)底邊彈出選擇列表,比較常用的選擇條件或跳轉(zhuǎn)方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-08-08
  • Android實(shí)現(xiàn)調(diào)用攝像頭拍照與視頻功能

    Android實(shí)現(xiàn)調(diào)用攝像頭拍照與視頻功能

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)調(diào)用攝像頭拍照與視頻功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-04-04
  • Android使用SqLite實(shí)現(xiàn)登錄注冊功能流程詳解

    Android使用SqLite實(shí)現(xiàn)登錄注冊功能流程詳解

    這篇文章主要介紹了使用Android Studio自帶的sqlite數(shù)據(jù)庫實(shí)現(xiàn)一個(gè)簡單的登錄注冊功能,SQLite是一個(gè)軟件庫,實(shí)現(xiàn)了自給自足的、無服務(wù)器的、零配置的、事務(wù)性的SQL數(shù)據(jù)庫引擎,本文給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2023-12-12
  • Android開發(fā)之Adobe flash操作工具類

    Android開發(fā)之Adobe flash操作工具類

    這篇文章主要介紹了Android開發(fā)之Adobe flash操作工具類,可實(shí)現(xiàn)flash的安裝及判斷flash是否安裝等功能,需要的朋友可以參考下
    2017-12-12
  • Android的支付密碼輸入框?qū)崿F(xiàn)淺析

    Android的支付密碼輸入框?qū)崿F(xiàn)淺析

    現(xiàn)在有很多的應(yīng)用都有支付密碼功能,而支付密碼的密碼輸入框確實(shí)一個(gè)很好玩的控件。雖然網(wǎng)上有很多例子,但是抽時(shí)間自己設(shè)計(jì)一個(gè)未嘗不可啊,下面來一起看看吧,有需要的朋友們可以參考學(xué)習(xí)。
    2016-09-09
  • Android 異步加載圖片分析總結(jié)

    Android 異步加載圖片分析總結(jié)

    研究了android從網(wǎng)絡(luò)上異步加載圖像,現(xiàn)總結(jié)如下,感興趣的朋友可以了解下哈
    2013-06-06
  • Android開發(fā)事件處理的代碼如何寫手摸手教程

    Android開發(fā)事件處理的代碼如何寫手摸手教程

    這篇文章主要為大家介紹了Android開發(fā)事件處理的代碼如何寫手摸手教程,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-02-02

最新評論