Android實現第三方登錄的上拉展開,下拉隱藏,下拉隱藏示例

Android的UI和交互是很重要的一部分,直接影響到用戶對軟件的體驗。隨著項目經驗的積累,發現Android中動畫的運用越來越重要。本篇文章抽出了項目登錄界面中實現的第三方登錄,用戶可以上拉展開,下拉隱藏第三方登錄這么一個效果,提高用戶和軟件的交互性。

創新互聯專注于企業成都全網營銷推廣、網站重做改版、太白網站定制設計、自適應品牌網站建設、HTML5、電子商務商城網站建設、集團公司官網建設、外貿營銷網站建設、高端網站制作、響應式網頁設計等建站業務,價格優惠性價比高,為太白等各大城市提供網站開發制作服務。

實現效果:

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; 
    } 
 
  } 
} 

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持創新互聯。

網站名稱:Android實現第三方登錄的上拉展開,下拉隱藏,下拉隱藏示例
轉載源于:http://m.kartarina.com/article34/pgoese.html

成都網站建設公司_創新互聯,為您提供定制開發網站內鏈云服務器外貿網站建設、移動網站建設搜索引擎優化

廣告

聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯

網站托管運營
主站蜘蛛池模板: 亚洲v国产v天堂a无码久久| 久久久无码精品亚洲日韩蜜臀浪潮 | 一本之道高清无码视频| 爽到高潮无码视频在线观看| 伊人蕉久中文字幕无码专区| 日韩国产精品无码一区二区三区| 在线观看无码AV网址| 亚洲精品无码午夜福利中文字幕 | 亚洲AV日韩AV永久无码绿巨人| 99精品国产在热久久无码| 国产精品无码一区二区在线观 | 中文无码字慕在线观看| 亚洲熟妇少妇任你躁在线观看无码 | 久久精品亚洲中文字幕无码麻豆| 韩国精品一区二区三区无码视频| 亚洲A∨无码一区二区三区| 无码专区国产精品视频| 亚洲av无码专区在线电影天堂| 国产成人亚洲综合无码精品| 精品无码专区亚洲| 亚洲AV无码AV日韩AV网站| 少妇人妻偷人精品无码视频新浪 | 中文字幕精品无码一区二区三区 | 国产成人精品一区二区三区无码| AV无码精品一区二区三区| 伊人久久无码中文字幕 | 中国少妇无码专区| 国产丝袜无码一区二区视频| 亚洲人成人伊人成综合网无码| 水蜜桃av无码一区二区| 国产亚洲大尺度无码无码专线| 乱人伦人妻中文字幕无码久久网| av中文无码乱人伦在线观看| 亚洲国产精品无码中文lv| 中文AV人妻AV无码中文视频| 亚洲中文无码av永久| 亚洲日韩看片无码电影| 成人免费午夜无码视频| 亚洲AV无码乱码麻豆精品国产| 91精品国产综合久久四虎久久无码一级 | 午夜无码熟熟妇丰满人妻|