最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android仿QQ可拉伸頭部控件

 更新時(shí)間:2019年11月16日 14:42:41   作者:gnifeifeiing  
這篇文章主要為大家詳細(xì)介紹了Android仿QQ可拉伸頭部控件,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Android仿QQ可拉伸頭部控件的具體實(shí)現(xiàn)代碼,供大家參考,具體內(nèi)容如下

該控件大致思路:

1.采用繼承l(wèi)istview加入頭部view。
2.監(jiān)聽listview滾動。
3.自定義動畫回彈。

先看效果吧:

activity-main.xml布局如下:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:orientation="horizontal"
 tools:context=".MainActivity" >

 <com.example.headerlistview.HeaderListView
 android:id="@+id/header_lv"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:cacheColorHint="@android:color/transparent"
 android:divider="@android:color/darker_gray"
 android:dividerHeight="1dip"
 android:duplicateParentState="true"
 android:scrollbars="none" >
 </com.example.headerlistview.HeaderListView>

</LinearLayout>

headerview.xml布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:orientation="vertical" >

 <ImageView 
 android:id="@+id/header_image"
 android:layout_width="match_parent"
 android:layout_height="150dip"
 android:scaleType="centerCrop"
 android:src="@drawable/lifei987"
 />

</LinearLayout>

list_item布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="80dip"
 android:gravity="center_vertical"
 android:orientation="horizontal" >
"

 <ImageView
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:src="@drawable/ic_launcher" />

 <LinearLayout
 android:layout_width="match_parent"
 android:layout_height="80dip"
 android:layout_marginLeft="10dip"
 android:orientation="vertical" >

 <TextView
 android:id="@+id/tv_name"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_marginTop="10dip"
 android:text="lifei" />

 <TextView
 android:id="@+id/tv_describe"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_marginTop="10dip"
 android:text="lifeiasdfasdfasfsadfasf" />
 </LinearLayout>

</LinearLayout>

activity代碼:

package com.example.headerlistview;

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

import android.os.Bundle;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class MainActivity extends Activity {

 private HeaderListView header_lv;

 private ImageView header_iv;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 getHeaderView();
 initView();
 }


 private void initView() {
 // TODO Auto-generated method stub
 header_lv=(HeaderListView) findViewById(R.id.header_lv);
 header_lv.addHeaderView(getHeaderView());
 header_lv.setHeaderView(header_iv);
 header_lv.setAdapter(getSimpleAdapter());
 }

 public BaseAdapter getSimpleAdapter(){
 List<Map<String, Object>> data=new ArrayList<Map<String,Object>>();
 for(int i=0;i<15;i++){
 Map<String, Object> map=new HashMap<String, Object>();
 map.put("name", "鄭州___"+i);
 map.put("describe", "asdfasdfasdfasdfasdfsadfsad");
 data.add(map);
 }

 SimpleAdapter simpleAdapter=new SimpleAdapter(this, data, R.layout.list_item, new String[]{"name","describe"}, new int[]{R.id.tv_name,R.id.tv_describe});
 return simpleAdapter;
 }

 public View getHeaderView(){
 View view= getLayoutInflater().inflate(R.layout.headerview, null);
 header_iv =(ImageView) view.findViewById(R.id.header_image);
 return view;
 }

}

自定義控件HeaderListView:

package com.example.headerlistview;

import java.security.spec.ECField;

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Transformation;
import android.widget.ImageView;
import android.widget.ListView;

public class HeaderListView extends ListView {

 private ImageView headerView;

 private int headerView_initHeight;//imageview初始高度

 public void setHeaderView(ImageView headerView) {
 this.headerView = headerView;
 }

 public HeaderListView(Context context) {
 super(context);
 // TODO Auto-generated constructor stub
 }

 public HeaderListView(Context context, AttributeSet attrs, int defStyle) {
 super(context, attrs, defStyle);
 // TODO Auto-generated constructor stub
 }

 public HeaderListView(Context context, AttributeSet attrs) {
 super(context, attrs);
 // TODO Auto-generated constructor stub
 }

 /**
 * listview焦點(diǎn)改變時(shí)--獲取iamgeview高度的初始值,該值不能在構(gòu)造方法中獲取
 */
 @Override
 public void onWindowFocusChanged(boolean hasWindowFocus) {
 // TODO Auto-generated method stub
 super.onWindowFocusChanged(hasWindowFocus);
 if(hasWindowFocus){
 this.headerView_initHeight=headerView.getHeight();
 }
 }

 @SuppressLint("NewApi") @Override
 protected boolean overScrollBy(int deltaX, int deltaY, int scrollX,
 int scrollY, int scrollRangeX, int scrollRangeY,
 int maxOverScrollX, int maxOverScrollY, boolean isTouchEvent) {
 // 滑動過頭的時(shí)候調(diào)用
 boolean bl=resizeHeaderView(deltaY);

 return bl?true:super.overScrollBy(deltaX, deltaY, scrollX, scrollY, scrollRangeX,
 scrollRangeY, maxOverScrollX, maxOverScrollY, isTouchEvent);
 }

 /**
 * 控制imageview高度的增加
 * @param deltaY 偏移量
 */
 private boolean resizeHeaderView(int deltaY) {
 if(Math.abs((double)deltaY)<200){
 if(deltaY<0){
 headerView.getLayoutParams().height=headerView.getHeight()-deltaY;
 //重新繪制
 headerView.requestLayout();
 }else{
 headerView.getLayoutParams().height=headerView.getHeight()-deltaY;
 headerView.requestLayout();
 }
 }

 return false;
 }

 @Override
 protected void onScrollChanged(int l, int t, int oldl, int oldt) {
 // TODO Auto-generated method stub
 super.onScrollChanged(l, t, oldl, oldt);
 //獲取imageview父控件
 View parent=(View) headerView.getParent();
 //當(dāng)父控件的top值小于零或者高度大于原始高度時(shí)觸發(fā)
 if(parent.getTop()<0||headerView.getHeight()>headerView_initHeight){
 headerView.getLayoutParams().height=headerView.getHeight()+parent.getTop();
 parent.layout(parent.getLeft(),0, parent.getRight(), parent.getHeight());
 headerView.requestLayout();
 }
 }

 @Override
 public boolean onTouchEvent(MotionEvent ev) {
 // TODO Auto-generated method stub
 if(ev.getAction()==MotionEvent.ACTION_UP||ev.getAction()==MotionEvent.ACTION_CANCEL){
 MyAnimation animation=new MyAnimation(headerView, headerView_initHeight);
 animation.setDuration(200);
 headerView.startAnimation(animation);
 }
 return super.onTouchEvent(ev);
 }

 public class MyAnimation extends Animation{

 private ImageView header_iv;
 private int currentHeight;
 private int targetHeight;
 private int poorHeight;

 public MyAnimation(ImageView iv,int targetHeight){
 this.header_iv=iv;
 this.targetHeight=targetHeight;
 this.currentHeight=iv.getHeight();
 this.poorHeight=this.currentHeight-this.targetHeight;
 }

 /**
 * 動畫執(zhí)行期間執(zhí)行該方法,不斷執(zhí)行
 * interpolatedTime:當(dāng)前時(shí)間與duration的時(shí)間比(時(shí)間執(zhí)行百分比)
 */
 @Override
 protected void applyTransformation(float interpolatedTime,
 Transformation t) {
 // TODO Auto-generated method stub
 super.applyTransformation(interpolatedTime, t);
 this.header_iv.getLayoutParams().height=(int)(currentHeight-poorHeight*interpolatedTime);
 this.header_iv.requestLayout();
 }
 }

}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android利用Intent實(shí)現(xiàn)記事本功能(NotePad)

    Android利用Intent實(shí)現(xiàn)記事本功能(NotePad)

    這篇文章主要為大家詳細(xì)介紹了Android利用Intent實(shí)現(xiàn)簡單記事本功能(NotePad)的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-06-06
  • Android實(shí)現(xiàn)邊錄邊播功能

    Android實(shí)現(xiàn)邊錄邊播功能

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)邊錄邊播功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-11-11
  • Android EditText長按菜單中分享功能的隱藏方法

    Android EditText長按菜單中分享功能的隱藏方法

    Android EditText控件是經(jīng)常使用的控件,下面這篇文章主要給大家介紹了關(guān)于Android中EditText長按菜單中分享功能的隱藏方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-02-02
  • Android開發(fā)之ListView列表刷新和加載更多實(shí)現(xiàn)方法

    Android開發(fā)之ListView列表刷新和加載更多實(shí)現(xiàn)方法

    這篇文章主要介紹了Android開發(fā)之ListView列表刷新和加載更多實(shí)現(xiàn)方法,實(shí)例分析了ListView列表操作的相關(guān)技巧,需要的朋友可以參考下
    2015-06-06
  • Kotlin中的反射機(jī)制深入講解

    Kotlin中的反射機(jī)制深入講解

    反射,簡單來說,是一種在運(yùn)行時(shí)動態(tài)地訪問對象屬性和方法的方式,而不需要事先確定這些屬性是什么。下面這篇文章主要給大家介紹了關(guān)于Kotlin中反射機(jī)制的相關(guān)資料,需要的朋友可以參考下
    2018-11-11
  • Android設(shè)置默認(rèn)鎖屏壁紙接口的方法

    Android設(shè)置默認(rèn)鎖屏壁紙接口的方法

    這篇文章主要介紹了Android默認(rèn)鎖屏壁紙接口的設(shè)置方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-01-01
  • Android組件之DrawerLayout實(shí)現(xiàn)抽屜菜單

    Android組件之DrawerLayout實(shí)現(xiàn)抽屜菜單

    DrawerLayout組件同樣是V4包中的組件,也是直接繼承于ViewGroup類,所以這個(gè)類也是一個(gè)容器類。接下來通過本文給大家介紹Android組件之DrawerLayout實(shí)現(xiàn)抽屜菜單,感興趣的朋友一起學(xué)習(xí)吧
    2016-02-02
  • android自由改變Dialog窗口位置的方法

    android自由改變Dialog窗口位置的方法

    這篇文章主要介紹了android自由改變Dialog窗口位置的方法,涉及Android操作Dialog窗口相關(guān)技巧,需要的朋友可以參考下
    2015-04-04
  • 仿ios狀態(tài)欄顏色和標(biāo)題欄顏色一致的實(shí)例代碼

    仿ios狀態(tài)欄顏色和標(biāo)題欄顏色一致的實(shí)例代碼

    下面小編就為大家分享一篇仿ios狀態(tài)欄顏色和標(biāo)題欄顏色一致的實(shí)例代碼,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-01-01
  • android studio編譯jar包或者aar包的方法教程詳解

    android studio編譯jar包或者aar包的方法教程詳解

    這篇文章主要介紹了android studio編譯jar包或者aar包的方法教程,本文通過圖文并茂的形式給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-03-03

最新評論

河南省| 巴彦县| 江华| 江源县| 乌拉特前旗| 永康市| 丰原市| 隆林| 永丰县| 咸阳市| 七台河市| 桃江县| 绵阳市| 正蓝旗| 泊头市| 平谷区| 利辛县| 霍林郭勒市| 遵义市| 田林县| 伊川县| 故城县| 台北市| 讷河市| 景泰县| 安顺市| 桂林市| 闸北区| 丰城市| 河北区| 叙永县| 驻马店市| 安岳县| 晋江市| 宕昌县| 海伦市| 柞水县| 广德县| 阿图什市| 丹巴县| 壶关县|