Android仿微信activity滑動關(guān)閉效果
Android仿微信activity滑動關(guān)閉功能
1.利用具體利用v4包下的slidingPaneLayout實(shí)現(xiàn)透明的activity,代碼如下:
BaseActivity:
public class BaseSlideCloseActivity extends AppCompatActivity implements
SlidingPaneLayout.PanelSlideListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
initSlideBackClose();
super.onCreate(savedInstanceState);
}
private void initSlideBackClose() {
if (isSupportSwipeBack()) {
SlidingPaneLayout slidingPaneLayout = new SlidingPaneLayout(this);
// 通過反射改變mOverhangSize的值為0,
// 這個mOverhangSize值為菜單到右邊屏幕的最短距離,
// 默認(rèn)是32dp,現(xiàn)在給它改成0
try {
Field overhangSize = SlidingPaneLayout.class.getDeclaredField("mOverhangSize");
overhangSize.setAccessible(true);
overhangSize.set(slidingPaneLayout, 0);
} catch (Exception e) {
e.printStackTrace();
}
slidingPaneLayout.setPanelSlideListener(this);
slidingPaneLayout.setSliderFadeColor(getResources()
.getColor(android.R.color.transparent));
// 左側(cè)的透明視圖
View leftView = new View(this);
leftView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
slidingPaneLayout.addView(leftView, 0);
ViewGroup decorView = (ViewGroup) getWindow().getDecorView();
// 右側(cè)的內(nèi)容視圖
ViewGroup decorChild = (ViewGroup) decorView.getChildAt(0);
decorChild.setBackgroundColor(getResources()
.getColor(android.R.color.white));
decorView.removeView(decorChild);
decorView.addView(slidingPaneLayout);
// 為 SlidingPaneLayout 添加內(nèi)容視圖
slidingPaneLayout.addView(decorChild, 1);
}
}
protected boolean isSupportSwipeBack() {
return true;
}
@Override
public void onPanelSlide(View panel, float slideOffset) {
}
@Override
public void onPanelOpened(View panel) {
finish();
}
@Override
public void onPanelClosed(View panel) {
}
}
activity 透明style:
<resources xmlns:tools="http://schemas.android.com/tools"> <!-- Base application theme. --> <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <!-- Customize your theme here. --> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> </style> <style name="DIY.SlideClose.Transparent.Theme" parent="AppTheme"> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:windowIsTranslucent">true</item> <item name="android:windowAnimationStyle">@style/DIY.Animation.SlidingBack</item> <item name="android:actionBarStyle">@style/DIYActionBar.Custom</item> </style> <style name="DIYActionBar.Custom" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse"> <item name="displayOptions">showCustom</item> <item name="android:background">@android:color/transparent</item> <item name="background">@android:color/transparent</item> <item name="android:displayOptions" tools:ignore="NewApi">showCustom</item> <item name="android:height">?actionBarSize</item> </style> <style name="DIY.Animation.SlidingBack" parent="@android:style/Animation.Activity"> <item name="android:activityOpenEnterAnimation">@anim/slide_in_right</item> <item name="android:activityOpenExitAnimation">@anim/slide_out_right</item> <item name="android:activityCloseEnterAnimation">@anim/slide_in_right</item> <item name="android:activityCloseExitAnimation">@anim/slide_out_right</item> <item name="android:wallpaperOpenEnterAnimation">@anim/slide_in_right</item> <item name="android:wallpaperOpenExitAnimation">@anim/slide_out_right</item> <item name="android:wallpaperCloseEnterAnimation">@anim/slide_in_right</item> <item name="android:wallpaperCloseExitAnimation">@anim/slide_out_right</item> <item name="android:wallpaperIntraOpenEnterAnimation">@anim/slide_in_right</item> <item name="android:wallpaperIntraOpenExitAnimation">@anim/slide_out_right</item> <item name="android:wallpaperIntraCloseEnterAnimation">@anim/slide_in_right</item> <item name="android:wallpaperIntraCloseExitAnimation">@anim/slide_out_right</item> </style> </resources>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Android 實(shí)現(xiàn)永久保存數(shù)據(jù)的方法詳解
本篇文章是對Android實(shí)現(xiàn)永久保存數(shù)據(jù)的方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06
解決Android中自定義DialogFragment解決寬度和高度問題
Android中自定義DialogFragment解決寬度和高度問題但是我們很多時候想把DialogFragment的高度固定,那么我們需要設(shè)置DialogFragment的高度,在Fragment的onResume()聲明周期方法中設(shè)置window的寬高即可2017-12-12
Android編程實(shí)現(xiàn)大圖滾動顯示的方法
這篇文章主要介紹了Android編程實(shí)現(xiàn)大圖滾動顯示的方法,涉及Android使用imageView配合onTouch事件操作圖片顯示的相關(guān)技巧,需要的朋友可以參考下2016-10-10
Android實(shí)現(xiàn)微信朋友圈評論EditText效果
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)微信朋友圈評論EditText效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-11-11
Android開發(fā)之電話撥號器和短信發(fā)送器實(shí)現(xiàn)方法
這篇文章主要介紹了Android開發(fā)之電話撥號器和短信發(fā)送器實(shí)現(xiàn)方法,結(jié)合實(shí)例形式較為詳細(xì)的分析了Android電話撥號器和短信發(fā)送器的具體原理與實(shí)現(xiàn)步驟,需要的朋友可以參考下2015-12-12
OpenGL ES 矩陣變換及其數(shù)學(xué)原理詳解(五)
這篇文章主要為大家詳細(xì)介紹了OpenGL ES 矩陣變換及其數(shù)學(xué)原理的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-05-05

