Android PullZoomView:PullToZoomListViewEx(1)
来源:互联网 发布:java foreach能倒序 编辑:程序博客网 时间:2024/05/16 15:39
Android PullZoomView:PullToZoomListViewEx(1)
Android PullZoomView是github上面的一个第三方开源项目,该项目实现的功能被新浪微博的移动端广泛使用,其效果就是,当用户在下拉过程中,头部的图片会有一定的拉伸,当用户松开时候,图片又收缩复位,其效果如动态图所示:
PullZoomView要实现两类,一类是典型的Android ListView,另外一类是Android 的scroll view。本文先介绍PullZoomView在ListView上的实现:PullToZoomListViewEx。
首先需要把PullToZoomListViewEx像ListView一样写进布局:
<RelativeLayout 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" tools:context="zhangphil.listview.MainActivity" > <com.ecloud.pulltozoomview.PullToZoomListViewEx xmlns:custom="http://schemas.android.com/apk/res-auto" android:id="@+id/listview" android:layout_width="match_parent" android:layout_height="match_parent" custom:headerView="@layout/head_view" custom:zoomView="@layout/head_zoom_view" /></RelativeLayout>
需要注意的是,需要定义一个headerView:
custom:headerView="@layout/head_view"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/layout_view" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="bottom" android:gravity="bottom"> <ImageView android:id="@+id/iv_user_head" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:src="@drawable/ic_launcher" /> <TextView android:id="@+id/tv_user_name" android:textSize="12sp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/iv_user_head" android:layout_centerHorizontal="true" android:text="http://blog.csdn.net/zhangphil" android:textColor="#ffffff" /> <LinearLayout android:id="@+id/ll_action_button" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#66000000" android:layout_alignParentBottom="true" android:padding="10dip"> <TextView android:id="@+id/tv_register" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="注册" android:layout_weight="1" android:textSize="12sp" android:gravity="center" android:layout_gravity="center" android:textColor="#ffffff" /> <TextView android:id="@+id/tv_login" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="登录" android:layout_weight="1" android:textSize="12sp" android:gravity="center" android:layout_gravity="center" android:textColor="#ffffff" /> </LinearLayout></RelativeLayout>
此处的headerView是位于PullToZoomListViewEx头部的一个子布局,里面定义一些控件将出现在PullToZoomListViewEx的头部,但此处的headerView并不会缩放,只是可以看到此处的headerView在随着下拉过程中移位。
而定义的custom:zoomView:
custom:zoomView="@layout/head_zoom_view"
<?xml version="1.0" encoding="utf-8"?><ImageView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/imageView" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center_horizontal" android:scaleType="centerCrop" android:src="@drawable/image" />head_zoom_view其实就是简单的放一张图片。
则是真正的要缩放伸展的View,此处通常会放置一张图片,在用户下拉过程中滑动缩放,产生奇妙的视觉效果。
在一定程度上讲,zoomView是衬托在headerView底下的。headerView是一个正常显示的Android View布局,而zoomView则是可以产生动态缩放和收缩效果的特殊zoom View。
写一个完整的例子加以说明。
Java代码:
package zhangphil.listview;import com.ecloud.pulltozoomview.PullToZoomListViewEx;import android.app.Activity;import android.os.Bundle;import android.util.DisplayMetrics;import android.util.Log;import android.view.View;import android.widget.AbsListView;import android.widget.AdapterView;import android.widget.ArrayAdapter;public class MainActivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);PullToZoomListViewEx listView = (PullToZoomListViewEx) findViewById(R.id.listview);String[] data=new String[100];for(int i=0;i<data.length;i++){data[i]="测试数据 @ Zhang Phil "+i;} listView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, data)); listView.getPullRootView().setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Log.d("position", "position = " + position); } }); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Log.d("position", "position = " + position); } }); setPullToZoomListViewExHeaderLayoutParams(listView);}//设置头部的View的宽高。privatevoidsetPullToZoomListViewExHeaderLayoutParams(PullToZoomListViewEx listView){ DisplayMetrics localDisplayMetrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(localDisplayMetrics); int mScreenHeight = localDisplayMetrics.heightPixels; int mScreenWidth = localDisplayMetrics.widthPixels; AbsListView.LayoutParams localObject = new AbsListView.LayoutParams(mScreenWidth, (int) (9.0f * (mScreenWidth / 16.0F))); listView.setHeaderLayoutParams(localObject);}}
运行的结果就是前文中的动态效果。
静态图1,此为初始状态:
静态图2,此为下拉伸展时候的状态:
头部的素材图片image.jpg原图:
附录:
【1】Android PullZoomView在github上的项目主页:https://github.com/Frank-Zhu/PullZoomView
- Android PullZoomView:PullToZoomListViewEx(1)
- Android PullZoomView:PullToZoomListViewEx(1)
- Android PullZoomView:PullToZoomScrollViewEx(2)
- PullZoomView
- PullZoomView
- Android自定义控件——PullZoomView
- Android自定义控件——PullZoomView
- Android自定义控件——PullZoomView
- 自定义ListView盘点-PullZoomView(28)
- PullZoomView使用
- 新浪微博登录界面上下拉伸图片--第三方开源--PullToZoomListViewEx(一)
- 新浪微博登录界面上下拉伸图片--第三方开源--PullToZoomListViewEx(二)
- [Android]ScrollView和ListView上方的headView的下拉放大效果-PullZoomView的使用篇
- 一探究竟之PullZoomView
- 拓展开源库PullZoomView适配瀑布流
- 上下拉伸图片-第三方开源-PullToZoomListViewEx 实现阻尼效果
- PullZoomView(一) 可下拉可以变大的headView开源项目
- 拓展自定义下拉缩放header的组件PullZoomView,增加对listView的下拉刷新和上拉更多
- 【Unix/Linux编程实践】文件系统:编写pwd
- WebSocket的过程与理解
- 【郝斌数据结构自学笔记】57-59_递归8 _ 汉诺塔_1线性结构总复习 2线性结构和非线性结构关系 3栈队列链表数组之间的关系【重点】
- 在win10+Linux Ubuntu双系统下安装win xp三系统的痛苦经历
- Java String StringBuffer StringBuilder
- Android PullZoomView:PullToZoomListViewEx(1)
- HDU 1207 汉诺塔II DP
- 利用 RecyclerView 实现垂直交错的网格
- CStdioFile Class
- Android
- Parquet_3. 在 Impala, Hive, Pig, MR中使用 Parquet File -- 待完善
- 【C语言提高30】二级指针强化训练
- 【郝斌数据结构自学笔记】60-65_树的定义_树的专业术语解释_树的分类_二叉树连续存【重点】_二叉树的链式存储_普通树的存储
- 连接数据库