新浪微博第三方登录界面上下拉伸图片之第三方开源PullToZoomListViewEx(二)

作者:Z2 时间:2021-07-25 04:52:35 

上篇文章给大家介绍了新浪微博第三方登录界面上下拉伸图片之第三方开源PullToZoomListViewEx(一),需要了解的朋友可以点击了解详情。

这是PullZoomView在ScrollView实现,Android PullZoomView在ScrollView的实现是:PullToZoomScrollViewEx

下载地址:https://github.com/Frank-Zhu/PullZoomView

本文要说的PullToZoomScrollViewEx则以另外一种方式在Java代码中动态的为PullZoomView装载View:


private void loadViewForPullToZoomScrollView(PullToZoomScrollViewEx scrollView) {
 View headView = LayoutInflater.from(this).inflate(R.layout.head_view, null);
 View zoomView = LayoutInflater.from(this).inflate(R.layout.head_zoom_view, null);
 View contentView = LayoutInflater.from(this).inflate(R.layout.content_view, null);
 scrollView.setHeaderView(headView);
 scrollView.setZoomView(zoomView);
 scrollView.setScrollContentView(contentView);
}

两点内容需要注意:

(1)所有Android PullZoomView的头部及缩放效果都可以关闭或者开启,具体方式就是通过改变设置各种方法的true或false值。以下是比较重要的几个方法:

setParallax(boolean b);

true则有视差效果,false则无。

setHideHeader(boolean b);

true则隐藏自己定义的head view,false则显示。

setZoomEnabled(boolean b);
true支持缩放,false不支持缩放。

默认的,


setParallax(true);
setHideHeader(false);
setZoomEnabled(true);

(2)PullZoomView中嵌套的子View,需要通过getPullRootView().findViewById(R.id.xxxx)这样的方式找出来,而不是直接的findViewById()。

下面给出一个完整例子加以说明。

先写一个布局:


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 xmlns:custom="http://schemas.android.com/apk/res-auto"
 android:layout_width="match_parent"
 android:layout_height="match_parent" >
 <com.ecloud.pulltozoomview.PullToZoomScrollViewEx
  android:id="@+id/scroll_view"
  android:layout_width="match_parent"
  android:layout_height="match_parent" />
</RelativeLayout>

Java代码:


package com.zzw.testpullzoomview_scrollview;
import com.ecloud.pulltozoomview.PullToZoomScrollViewEx;
import android.app.Activity;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.LinearLayout;
public class MainActivity extends Activity {
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  // 注意初始化顺序,不要弄乱,否则抛出运行时空指针
  PullToZoomScrollViewEx scrollView = (PullToZoomScrollViewEx) findViewById(R.id.scroll_view);
  loadViewForPullToZoomScrollView(scrollView);
  scrollView.getPullRootView().findViewById(R.id.tv_test).setOnClickListener(new View.OnClickListener() {
   @Override
   public void onClick(View v) {
    Log.d("PullToZoomScrollViewEx", "onClick");
   }
  });
  scrollView.getPullRootView().findViewById(R.id.tv_test).setOnClickListener(new View.OnClickListener() {
   @Override
   public void onClick(View v) {
    Log.e("PullToZoomScrollViewEx", "onClick");
   }
  });
  scrollView.getPullRootView().findViewById(R.id.tv_test).setOnClickListener(new View.OnClickListener() {
   @Override
   public void onClick(View v) {
    Log.d("PullToZoomScrollViewEx", "onClick");
   }
  });
  setPullToZoomViewLayoutParams(scrollView);
 }
 private void loadViewForPullToZoomScrollView(PullToZoomScrollViewEx scrollView) {
  View headView = LayoutInflater.from(this).inflate(R.layout.head_view, null);
  View zoomView = LayoutInflater.from(this).inflate(R.layout.head_zoom_view, null);
  View contentView = LayoutInflater.from(this).inflate(R.layout.content_view, null);
  scrollView.setHeaderView(headView);
  scrollView.setZoomView(zoomView);
  scrollView.setScrollContentView(contentView);
 }
 // 设置头部的View的宽高。
 private void setPullToZoomViewLayoutParams(PullToZoomScrollViewEx scrollView) {
  DisplayMetrics localDisplayMetrics = new DisplayMetrics();
  getWindowManager().getDefaultDisplay().getMetrics(localDisplayMetrics);
  int mScreenHeight = localDisplayMetrics.heightPixels;
  int mScreenWidth = localDisplayMetrics.widthPixels;
  LinearLayout.LayoutParams localObject = new LinearLayout.LayoutParams(mScreenWidth,
    (int) (.F * (mScreenWidth / .F)));
  scrollView.setHeaderLayoutParams(localObject);
 }
}

 java代码需要的子布局:

head_view.xml:


<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="sp"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_below="@id/iv_user_head"
  android:layout_centerHorizontal="true"
  android:text="新浪微博"
  android:textColor="#ffffff" />
 <LinearLayout
  android:id="@+id/ll_action_button"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:background="#"
  android:layout_alignParentBottom="true"
  android:padding="dip">
  <TextView
   android:id="@+id/tv_register"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:text="注册"
   android:layout_weight=""
   android:textSize="sp"
   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=""
   android:textSize="sp"
   android:gravity="center"
   android:layout_gravity="center"
   android:textColor="#ffffff" />
 </LinearLayout>
</RelativeLayout>

head_zoom_view.xml:


<?xml version="." encoding="utf-"?>
<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/a" />

head_zoom_view其实就放了一张可供缩放拉伸的图片。

content_view.xml:


<?xml version="." encoding="utf-"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:background="#ffffff"
 android:orientation="vertical" >
 <TextView
  android:id="@+id/tv_test"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:gravity="center_vertical"
  android:padding="dp"
  android:text="test"
  android:textSize="sp" />
 <TextView
  android:id="@+id/tv_test"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:gravity="center_vertical"
  android:padding="dp"
  android:text="test"
  android:textSize="sp" />
 <TextView
  android:id="@+id/tv_test"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:gravity="center_vertical"
  android:padding="dp"
  android:text="test"
  android:textSize="sp" />
 <TextView
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:gravity="center_vertical"
  android:padding="dp"
  android:text="test"
  android:textSize="sp" />
 <TextView
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:gravity="center_vertical"
  android:padding="dp"
  android:text="test"
  android:textSize="sp" />
 <TextView
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:background="#eeeeee" />
 <TextView
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:gravity="center_vertical"
  android:padding="dp"
  android:text="test"
  android:textSize="sp" />
 <TextView
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:gravity="center_vertical"
  android:padding="dp"
  android:text="test"
  android:textSize="sp" />
 <TextView
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:gravity="center_vertical"
  android:padding="dp"
  android:text="test"
  android:textSize="sp" />
 <TextView
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:gravity="center_vertical"
  android:padding="dp"
  android:text="test"
  android:textSize="sp" />
 <TextView
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:gravity="center_vertical"
  android:padding="dp"
  android:text="test"
  android:textSize="sp" />
</LinearLayout>

实际开发中,如果确定要用ScrollView包括自己项目中的子View,那么content_view.xml就是其他View的装载“父”布局。重点需要在content_view.xml中展开。

标签:新浪微博第三方登录,pulltozoomlistviewex
0
投稿

猜你喜欢

  • android开发仿ios的UIScrollView实例代码

    2023-08-07 01:55:20
  • Java String 拼接字符串原理详解

    2023-05-14 10:10:33
  • C#设计模式之Mediator中介者模式解决程序员的七夕缘分问题示例

    2021-10-05 16:28:14
  • Android 中使用RadioGroup和Fragment实现底部导航栏的功能

    2022-07-17 16:11:04
  • C#判断字符串是否存在字母及字符串中字符的替换实例

    2022-04-15 03:49:48
  • android实现图片反转效果

    2022-09-24 20:48:11
  • Mybatis配置解析看这一篇就够了

    2023-05-15 22:42:12
  • 浅谈Java编程中string的理解与运用

    2021-05-31 22:15:44
  • Springboot如何根据实体类生成数据库表

    2023-11-20 13:54:39
  • java8 实现提取集合对象的每个属性

    2023-10-17 19:37:27
  • Android短信验证码(用的Mob短信验证)

    2022-12-16 15:22:41
  • Android自定义边缘凹凸的卡劵效果

    2023-03-16 09:58:46
  • C++中的long long与__int64

    2022-03-06 01:55:05
  • Android 添加TextView删除线(代码简单)

    2022-05-27 16:48:47
  • 利用Java简单实现一个代码行数统计器方法实例

    2023-01-12 10:50:25
  • 解决mybatis update并非所有字段需要更新问题

    2022-12-09 10:20:55
  • C++ pair的用法案例详解

    2021-09-21 01:40:20
  • 利用java实现单词倒序排列

    2023-07-01 04:30:51
  • Java数据结构之红黑树的真正理解

    2022-07-16 01:36:16
  • Java实现答答租车系统

    2022-07-12 01:38:17
  • asp之家 软件编程 m.aspxhome.com