Activit跳轉(zhuǎn)動畫之界面上某個位置并裂開上下拉伸動畫跳轉(zhuǎn)
需求:Activity(fragment)跳轉(zhuǎn)的時候當前界面裂開,上下各自拉出手機屏幕,之后跳轉(zhuǎn)到相對應的Activity.整體效果圖如下
思路:1,在當前Activity中截取當前手機的屏幕獲取到bitmap,然后根據(jù)具體位置(比如這里是掃碼圖標中間裂開)計算獲取到,中間裂開距離手機上和下的距離,在傳遞給跳轉(zhuǎn)后的Activity
(跳轉(zhuǎn)前的Activity做兩件事情,1,截取屏幕獲取bitmap2,計算出具體裂開位置距離屏幕上下的距離,傳遞給第二個activity方便來切割真?zhèn)€截圖)
2,跳轉(zhuǎn)后的Activity執(zhí)行動畫即可
(,(我上面分析的沒有帶上我截圖中自帶兩個view風別跟著上下圖已啟動的如果需要的話可以私密我))

整體的效果就如上圖,1,點擊掃碼 2,中間裂開執(zhí)行上線拉伸動畫,(這個時候是可以看見需要跳轉(zhuǎn)的Activity的)3,動畫結束
具體實現(xiàn)
一:跳轉(zhuǎn)前activity的截屏獲取bitmap,并且獲取到裂開位置的數(shù)值,傳遞給第二個activity,方便之后的切割
//這個bitmap我是用public static Bitmap bitmap;接受的方便第二個activity直接獲取 bitmap = ScreenShot.takeScreenShot(getActivity());
**//這個是工具類直接調(diào)用就可以獲取到手機屏幕了
package com.lzyc.ybtappcal.util;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Rect;
import android.view.View;
import com.lzyc.ybtappcal.activity.LoaddingSleepActivity;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
* Created by lovelin on 2016/7/20.
*/
public class ScreenShot {
private static int mHiddenViewMeasureHeight; //中間切割的高度
private static int screenHeightPixels; //屏幕高度
// 獲取指定Activity的截屏,保存到png文件
public static Bitmap takeScreenShot(Activity activity) {
// View是你需要截圖的View
View view = activity.getWindow().getDecorView();
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
Bitmap b1 = view.getDrawingCache();
// 獲取狀態(tài)欄高度
Rect frame = new Rect();
activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
int statusBarHeight = frame.top;
LogUtil.e("TAG", "" + statusBarHeight);
// 獲取屏幕長和高
int width = activity.getWindowManager().getDefaultDisplay().getWidth();
int height = activity.getWindowManager().getDefaultDisplay()
.getHeight();
// 去掉標題欄
// Bitmap b = Bitmap.createBitmap(b1, 0, 25, 320, 455);
Bitmap b = Bitmap.createBitmap(b1, 0, statusBarHeight, width, height
- statusBarHeight);
view.destroyDrawingCache();
return b;
}
// 保存到sdcard
private static void savePic(Bitmap b, String strFileName) {
FileOutputStream fos = null;
try {
fos = new FileOutputStream(strFileName);
if (null != fos) {
b.compress(Bitmap.CompressFormat.PNG, 90, fos);
fos.flush();
fos.close();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
// 程序入口
public static void shoot(Activity a) {
// ScreenShot.savePic(ScreenShot.takeScreenShot(a), "sdcard/xx.png");
}
}
1,獲取當前掃描按鈕中間的距離,
private void getMessureHeight() {
v.id_linea_top.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
public void onGlobalLayout() {
int imageHanlfHeight = (v.iv_fg_top.getBottom() - v.iv_fg_top.getTop()) / 2; //image 的一半高度
int bottom = v.iv_fg_top.getBottom();
/**
*imageview掃描按鈕底部距離 - 按鈕本身一半的距離 = 距離手機頂部的距離(就是播放動畫需要截取的上半圖片的高度)
*/
midData = bottom - imageHanlfHeight;
v.id_linea_top.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
});
}
2,*緊接著界面跳轉(zhuǎn)傳遞參數(shù)midData 即可
Bundle mBundle = new Bundle();
mBundle.putInt(Contants.KEY_PAGE_SEARCH, Contants.VAL_PAGE_SEARCH_TOP);
mBundle.putInt("midData", midData);
mBundle.putInt("h", h);
mBundle.putInt("topSplitHeight", topSplitHeight);
openActivityNoAnim(CaptureActivity.class, mBundle);
3,*跳轉(zhuǎn)取消系統(tǒng)動畫
public void openActivityNoAnim(Class<? extends Activity> ActivityClass, Bundle b) {
Intent intent = new Intent(mContext, ActivityClass);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
intent.putExtras(b);
startActivity(intent);
}
二:代碼截取上一個activity(fragment)的bitmap分成兩個執(zhí)行動畫的bitmap
private void cutting() {
// 切割第一個圖
bitmapTop = Bitmap.createBitmap(TopFragment.bitmap, 0, 0, TopFragment.bitmap.getWidth(), this.midData);
//且第二個圖
bitmapBottom = Bitmap.createBitmap(TopFragment.bitmap, 0, this.midData, TopFragment.bitmap.getWidth(), TopFragment.bitmap.getHeight() - midData);
}
1,在第二個Activity最外層先一個相對布局蓋在上面用來執(zhí)行動畫我閑的布局如下(這里我只貼出在外層的布局,里面需要顯示的布局就不寫了)
<最外層有一個相對布局,這里就不寫了只寫一個播放動畫的布局> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <LinearLayout android:id="@+id/id_linear_capture_top" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <ImageView android:id="@+id/loading_iv_top" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout> <LinearLayout android:id="@+id/id_linear_capture_under" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <ImageView android:id="@+id/loading_iv_bottm" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout> </LinearLayout>
2,找到view,設置他們上下需要執(zhí)行動畫的bitmap
/**
* 播放動畫
*/
private void startAnima() {
cutting();
final ImageView loading_iv_top = (ImageView) findViewById(R.id.loading_iv_top);
final ImageView loading_iv_bottm = (ImageView) findViewById(R.id.loading_iv_bottm);
id_linear_capture_top = (LinearLayout) findViewById(R.id.id_linear_capture_top);
id_linear_capture_under = (LinearLayout) findViewById(R.id.id_linear_capture_under);
final RelativeLayout id_relative_capture = (RelativeLayout) findViewById(R.id.id_relative_capture);
//設置上下播放拉伸圖片
loading_iv_top.setImageBitmap(this.bitmapTop);
loading_iv_bottm.setImageBitmap(this.bitmapBottom);
id_relative_capture.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
public void onGlobalLayout() {
//設置了圖片所以在這里獲取他們兩個的高,就是執(zhí)行動畫的距離
topHeight = loading_iv_top.getHeight(); //id_linear_capture_top id_linear_capture_under
bottonHeight = loading_iv_bottm.getHeight();
ObjectAnimator animator = ObjectAnimator.ofFloat(id_linear_capture_top, "translationY", 0, -topHeight);
ObjectAnimator animator1 = ObjectAnimator.ofFloat(id_linear_capture_under, "translationY", 0, bottonHeight);
AnimatorSet animSet = new AnimatorSet();
animSet.play(animator).with(animator1);
animSet.setDuration(400);
animSet.start();
id_relative_capture.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
});
}
3,到此動畫打開操作完畢,(我上面分析的沒有帶上我截圖中自帶兩個view風別跟著上下圖已啟動的如果需要的話可以私密我)
最后總結:1,當前截屏獲取bitmap2,第二個activity剪切上線需要執(zhí)行動畫的bitma3,在執(zhí)行動畫(這里只寫打開的動畫關閉的同理也就是一個動畫而已)
- 在uiview 的tableView中點擊cell進入跳轉(zhuǎn)到另一個界面的實現(xiàn)方法
- 總結IOS界面間跳轉(zhuǎn)的幾種方法
- IOS應用內(nèi)跳轉(zhuǎn)系統(tǒng)設置相關界面的方法
- IOS程序開發(fā)之跳轉(zhuǎn)短信發(fā)送界面實現(xiàn)發(fā)送短信功能
- Android編程使用Fragment界面向下跳轉(zhuǎn)并一級級返回的實現(xiàn)方法
- php+js iframe實現(xiàn)上傳頭像界面無跳轉(zhuǎn)
- JS 退出系統(tǒng)并跳轉(zhuǎn)到登錄界面的實現(xiàn)代碼
- Android中應用界面主題Theme使用方法和頁面定時跳轉(zhuǎn)應用
- asp.net textbox javascript實現(xiàn)enter與ctrl+enter互換 文本框發(fā)送消息與換行(類似于QQ)
- js實現(xiàn)界面向原生界面發(fā)消息并跳轉(zhuǎn)功能
相關文章
View事件分發(fā)原理和ViewPager+ListView嵌套滑動沖突
這篇文章主要介紹了View事件分發(fā)原理和ViewPager+ListView嵌套滑動沖突,文章圍繞主題展開詳細的內(nèi)容介紹,具有一定的參考價,需要的小伙伴可以參考一下2022-05-05
Android使用Notification在狀態(tài)欄上顯示通知
這篇文章主要為大家詳細介紹了Android使用Notification在狀態(tài)欄上顯示通知,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-12-12
Android組件TabHost實現(xiàn)頁面中多個選項卡切換效果
這篇文章主要為大家詳細介紹了Android組件TabHost實現(xiàn)頁面中多個選項卡切換效果的相關資料,感興趣的小伙伴們可以參考一下2016-05-05
android使用intent傳遞參數(shù)實現(xiàn)乘法計算
這篇文章主要為大家詳細介紹了android使用intent傳遞參數(shù)實現(xiàn)乘法計算,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-04-04

