Android实现第三方登录的上拉展开,下拉隐藏,下拉隐藏示例

Android的UI和交互是很重要的一部分,直接影响到用户对软件的体验。随着项目经验的积累,发现Android中动画的运用越来越重要。本篇文章抽出了项目登录界面中实现的第三方登录,用户可以上拉展开,下拉隐藏第三方登录这么一个效果,提高用户和软件的交互性。

实现效果:

(1)activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<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="com.example.propertyanimation.MainActivity"> 

  <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:orientation="vertical"> 

    <RelativeLayout
      android:id="@+id/re_ControlshowhideView"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_marginBottom="10dp"
      android:orientation="vertical"> 

      <RelativeLayout
        android:id="@+id/re_showarrowhead"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"> 

        <View
          android:layout_width="match_parent"
          android:layout_height="0.1dp"
          android:layout_marginLeft="12dp"
          android:layout_marginRight="12dp"
          android:layout_marginTop="17dip"
          android:background="#dadada" /> 

        <ImageView
          android:id="@+id/arrowhead"
          android:layout_width="30dip"
          android:layout_height="30dip"
          android:layout_centerInParent="true"
          android:src="@drawable/jiantoubelow" /> 

      </RelativeLayout> 

      <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/re_showarrowhead"
        android:layout_marginTop="10dp"
        android:gravity="center"
        android:text="-其他登录方式-" /> 

    </RelativeLayout> 

    <RelativeLayout
      android:id="@+id/showhideView"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_below="@id/re_ControlshowhideView"
      android:gravity="center"
      android:visibility="gone"
      android:orientation="vertical"> 

      <Button
        android:id="@+id/btn_qq"
        android:layout_width="40dp"
        android:layout_height="57.5dp"
        android:layout_gravity="center_vertical"
        android:layout_marginLeft="10dp"
        android:background="@drawable/qqlogin"
        android:clickable="true"
        android:gravity="center"
        android:paddingLeft="10dp"
        android:textSize="16sp" /> 

      <Button
        android:id="@+id/btn_weixin"
        android:layout_width="40dp"
        android:layout_height="57.5dp"
        android:layout_gravity="center_vertical"
        android:layout_marginLeft="10dp"
        android:layout_toRightOf="@+id/btn_qq"
        android:background="@drawable/weixinlogin"
        android:clickable="true"
        android:gravity="center"
        android:paddingLeft="10dp"
        android:textSize="16sp" />
    </RelativeLayout> 

  </RelativeLayout> 

</RelativeLayout>

(2)PropertyAnimation.java  这个文件主要是把实现的属性动画封装到一个类里,这样一个功能就成为一个模块。其它调用者也可以很方便的使用。

package com.example.propertyanimation; 

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation; 

public class PropertyAnimation { 

  private float mDensity; 

  private int mHiddenViewMeasuredHeight; //点击箭头的时候,需要隐藏的控件最终到达一个高度,
                      // 这个就是我们要控件到达的目标值。 

  public PropertyAnimation(Context context){
    //点击箭头的时候,需要隐藏的控件最终到达一个高度,这个就是我们的目标值,只需要通过布局中的dp转换成像素就行了。
    mDensity = context.getResources().getDisplayMetrics().density;
    mHiddenViewMeasuredHeight = (int) (mDensity * 57.5 + 0.5);
  } 

  public void animateOpen(View v) {
    v.setVisibility(View.VISIBLE);
    //createDropAnimator()自定义的一个动画效果函数
    ValueAnimator animator = createDropAnimator(v, 0,
        mHiddenViewMeasuredHeight);
    animator.start();
  } 

  /**
   * 给控制动画的箭头设置动画.
   * 给箭头设置向上的动画
   * @param view  控件
   */
  public void animationIvOpen(View view) {
    //旋转动画,参数说明:new RotateAnimation(旋转的开始角度,旋转的结束角度,X轴的伸缩模式:可以取值为ABSOLUTE、
    // RELATIVE_TO_SELF、RELATIVE_TO_PARENT,X坐标的伸缩值,Y轴的伸缩模式:可以取值为ABSOLUTE、RELATIVE_TO_SELF、
    // RELATIVE_TO_PARENT,Y坐标的伸缩值);
    RotateAnimation animation = new RotateAnimation(0, 180,
        Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
        0.5f);
    //动画执行完后是否停留在执行完的状态
    animation.setFillAfter(true);
    //持续时间
    animation.setDuration(100);
    //为箭头图片绑定动画
    view.startAnimation(animation);
  } 

  /**
   * 给控制动画的箭头设置动画.
   * 给箭头设置向下的动画
   * @param view
   */
  public void animationIvClose(View view) {
    RotateAnimation animation = new RotateAnimation(180, 0,
        Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
        0.5f);
    animation.setFillAfter(true);
    animation.setDuration(100);
    view.startAnimation(animation);
  } 

  /**
   * 设置隐藏动画
   *
   * @param view //动画作用的控件
   */
  public void animateClose(final View view) {
    //获得控件的高度
    int origHeight = view.getHeight();
    //createDropAnimator()自定义的一个动画效果函数
    ValueAnimator animator = createDropAnimator(view, origHeight, 0);
    //如果你不想实现Animator.AnimatorListener中的所有接口,你可以通过继承AnimatorListenerAdapter。
    //AnimatorListenerAdapter类为所有的方法提供了一个空实现,所以你可以根据需要实现你需要的,覆盖AnimatorListenerAdapter原来的方法
    animator.addListener(new AnimatorListenerAdapter() {
      @Override
      public void onAnimationEnd(Animator animation) {  //动画结束时调用
        view.setVisibility(View.GONE);
      }
    });
    animator.start();
  } 

  /**
   * 自定义的动画效果
   *
   * @param v   //动画作用的控件
   * @param start //动画的开始值
   * @param end  //动画的结束值
   * @return
   */
  private ValueAnimator createDropAnimator(final View v, int start, int end) {
    //这里我们利用ValueAnimator.ofInt创建了一个值从start到end的动画
    ValueAnimator animator = ValueAnimator.ofInt(start, end);
    //为ValueAnimator注册AnimatorUpdateListener监听器,在该监听器中可以
    // 监听ValueAnimator计算出来的值的改变,并将这些值应用到指定对象
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 

      @Override
      public void onAnimationUpdate(ValueAnimator arg0) {
        //获取动画当前值
        int value = (int) arg0.getAnimatedValue();
        //得到控件的属性集合
        ViewGroup.LayoutParams layoutParams = v.getLayoutParams();
        //设置控件的高属性
        layoutParams.height = value;
        //把属性绑定到需要动画的控件上
        v.setLayoutParams(layoutParams);
      }
    });
    return animator;
  } 

}

(3)MainActivity.java 这个文件开始使用封装好的属性动画了。

package com.example.propertyanimation; 

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.Toast; 

public class MainActivity extends Activity implements View.OnClickListener{ 

  private ImageView mIv_arrowhead; 

  private RelativeLayout mHiddenLayout; 

  private PropertyAnimation propertyAnimation; 

  private Button btn_qq;  //QQ登录按钮 

  private Button btn_weixin;  //微信登录按钮 

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    //自己定义的属性动画类
    propertyAnimation=new PropertyAnimation(this);
    //隐藏/显示第三方登录的箭头图标
    mIv_arrowhead = (ImageView) this.findViewById(R.id.arrowhead);
    mIv_arrowhead.setOnClickListener(this);
    //隐藏/显示的布局
    mHiddenLayout = (RelativeLayout) this.findViewById(R.id.showhideView);
    //QQ登录
    btn_qq = (Button) this.findViewById(R.id.btn_qq);
    btn_qq.setOnClickListener(this);
    //微信登录
    btn_weixin=(Button)this.findViewById(R.id.btn_weixin);
    btn_weixin.setOnClickListener(this); 

  } 

  @Override
  public void onClick(View v) {
    switch (v.getId()) {
      case R.id.arrowhead:
        if (mHiddenLayout.getVisibility() == View.GONE) {
          propertyAnimation.animateOpen(mHiddenLayout);
          propertyAnimation.animationIvOpen(mIv_arrowhead);
        } else {
          propertyAnimation.animateClose(mHiddenLayout);
          propertyAnimation.animationIvClose(mIv_arrowhead);
        }
        break;
      case R.id.btn_qq:   //QQ授权登录
        Toast.makeText(this,"QQ登录",Toast.LENGTH_SHORT).show();
        break;
      case R.id.btn_weixin: //微信授权登录
        Toast.makeText(this,"微信登录",Toast.LENGTH_SHORT).show();
        break;
    } 

  }
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。

(0)

相关推荐

  • Android实现使用微信登录第三方APP的方法

    本文实例讲述了Android实现使用微信登录第三方APP的方法.分享给大家供大家参考,具体如下: 使用微信登录APP,免去注册过程,现在已经有很多的类似应用了.集成该功能过程不复杂,但还是有一些地方需要注意的. 开始之前,需要做下面的准备工作. 1.到微信开放平台注册你的APP,并申请开通微信登录的权限.参考这里: https://open.weixin.qq.com// 2.下载Android SDK和签名查看工具,请参考: https://open.weixin.qq.com/cgi-bin

  • Android第三方登录之腾讯QQ登录的实例代码

    布局文件 <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="登录成功" android:textSize="25sp" android:layout_marginTop="100dp" /> 清单文件中的配置 <activity android:n

  • Android 第三方登录、分享(ShareSDK、友盟)

    为下边的项目做准备,写一个第三方登录.分享的demo.分别使用sharesdk和友盟来实现. 先说一下我对两者的使用上的感觉,个人感觉sharesdk比友盟更好一点,好在哪里呢?好在人工服务上.在集成的过程中遇到了各种问题,但是sharesdk的人工服务做的很好,能给答疑解惑,提供解决问题的方法! 接下来上代码(本文使用android studio开发,sharesdk版本v2.7.7,友盟版本v6.0.0): 一.使用sharesdk(sharesdk版本v2.7.7)来集成: 1.要去官网:

  • 微信第三方登录Android实现代码

    记录一下微信第三方实现登录的方法.还是比较简单. 一.必要的准备工作 1.首先需要注册并被审核通过的微信开放平台帐号,然后创建一个移动应用,也需要被审核: 2.然后到资源中心下载开发微信所需的工具: 下载的网址:点击打开链接,有一个是SDK,一个是签名生成工具还有一个范例代码. 3.将SDK文件夹lib下的jar文件libammsdk.jar导入到项目工程中: 4.你的测试手机需要装好微信客户端: 5.在项目的AndroidManifest.xml文件中添加如下的权限: <uses-permis

  • Android微信第三方登录(个人笔记)

    今天在写微信登录,花了半天时间搞定.然后写下自己的笔记,希望帮助更多的人.欢迎各位指教. 微信授权登录,官方说的不是很清楚.所以导致有一部分的坑. 微信注册应用平台的应用签名,下载 微信签名生成工具 输入项目的packageName也可以查看到. (注意:debug.Release 一定要区分,因为2种生成的微信签名不一致,会导致没有跳转.回调....一般在微信开发者上面注册的是正式环境打包好的.) 申请微信开发者账号.应用申请省略. 1. AndroidManifest.xml 权限 <!--

  • Android调用第三方QQ登录代码分享

    本文为大家分享了调用QQ登录的相关代码,希望对大家有帮助,减少项目开发的时间,具体内容如下 1.去QQ开放平台注册帐号(http://open.qq.com/),为应用申请QQ的APP_ID , 并下载相关的jar包,放到工程的lib目录下. 2.在Manifest.xml里注册QQ相关的Activity,代码如下 <activity android:name="com.tencent.connect.common.AssistActivity" android:screenOr

  • Android实现第三方授权登录、分享以及获取用户资料

    由于公司项目的需要,要实现在项目中使用第三方授权登录以及分享文字和图片等这样的效果,几经波折,查阅了一番资料,做了一个Demo.实现起来的效果还是不错的,不敢独享,决定写一个总结的教程,供大家互相交流.学习和参考,只求能和大家共同进步.希望能多多支持! 这篇文章中,我们使用到了Share SDK,它是为iOS.Android.WP8的APP提供社会化功能的一个组件,目前支持如QQ.微信.新浪微博.腾讯微博.开心网.人人网.豆瓣.网易微博.搜狐微博.facebook.twitter.google+

  • Android集成新浪微博第三方登录的方法

    本文实例讲述了Android集成新浪微博第三方登录的方法.分享给大家供大家参考.具体实现方法如下: 1.下载微博的sdk ,导入微博的jar包两个 android-support-v4.jar和weibosdkcore.jar两个包 2.把新浪微博中的demo_src中SDK中的com,导入到项目中 3.用demo中的constants,主要是参数设置,将里面的参数改成自己的参数. 4.编写代码,主要步骤如下: 复制代码 代码如下: // 初始化微博对象 mWeiboAuth = new Wei

  • Android第三方登录之QQ登录

    本文实例为大家分享了Android第三方登录之QQ的具体代码,供大家参考,具体内容如下 第三方登录之QQ 代码区 public class MainActivity extends AppCompatActivity { private Button btn; private TextView tv; private ImageView image; @Override protected void onCreate(Bundle savedInstanceState) { super.onCr

  • Android实现第三方登录的上拉展开,下拉隐藏,下拉隐藏示例

    Android的UI和交互是很重要的一部分,直接影响到用户对软件的体验.随着项目经验的积累,发现Android中动画的运用越来越重要.本篇文章抽出了项目登录界面中实现的第三方登录,用户可以上拉展开,下拉隐藏第三方登录这么一个效果,提高用户和软件的交互性. 实现效果: (1)activity_main.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android=&q

  • Android 友盟第三方登录与分享的实现代码

    前言 最近项目中又一次需要集成友盟的三方登录与分享,之前没有记录过,所以这次来写一下... 准备工作 1.注册友盟账号创建应用,获取key:申请地址 http://www.umeng.com 2.对对应的平台(腾讯.微信.新浪等等)申请第三方账号,获取key和密码 集成步骤 因为shareSDK分享与第三方登录集成方式类似(共用jar包),所以我就一起说了. 1.下载shareSDK分享的SDK 下载地址: https://developer.umeng.com/sdk 2.导入jar与res

  • Android实现上拉加载更多以及下拉刷新功能(ListView)

    首先为大家介绍Andorid5.0原生下拉刷新简单实现. 先上效果图: 相对于上一个19.1.0版本中的横条效果好看了很多.使用起来也很简单. <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/container" and

  • Android属性动画实现布局的下拉展开效果

    在Android的3.0之后,google又提出了属性动画的这样一个框架,他可以更好的帮助我们实现更丰富的动画效果.所以为了跟上技术的步伐,今天就聊一聊属性动画. 这一次的需求是这样的:当点击一个View的时候,显示下面隐藏的一个View,要实现这个功能,需要将V iew的visibility属性设置gone为visible即可,但是这个过程是一瞬间的,并不能实现我们要的效果.所以,属性动画是个不错的方案. 先把效果贴上 第一个:  第二个: 前面的这个是隐藏着,后面这个是显示的.当点击这个箭头

  • Android实现QQ的第三方登录和分享

    本文实例为大家分享了Android实现QQ的第三方登录的具体代码,供大家参考,具体内容如下 MainActivity.java /** * 实现QQ的第三方登录 * 1.搭建环境 (添加Jar包,添加Res图片,布局,Values资源,添加权限,配置Activity信息,修改Key值,build签名配置,Application初始化) * 2.写布局 * 3.登录的代码 * 注意:必须用真机测试 */ public class MainActivity extends AppCompatActi

随机推荐