Android仿微信activity滑动关闭效果

www.bjxdzj.com 更新:2017-03-01 编辑:kepeer 来源:转载
Android仿微信activity滑动关闭效果怎么实现?本文详细介绍了Android实现仿微信activity滑动关闭效果的教程,有兴趣的同学快来看看吧。

mg电子:马英九来到南投暨南大学演讲  【环球网综合报道】泄密案风波刚告一段落,台湾地区前领导人马英九并没闲下来。

1.利用具体利用v4包下的slidingPaneLayout实现透明的activity,代码如下:

 

 代码如下 复制代码

BaseActivity:

publicclassBaseSlideCloseActivityextendsAppCompatActivityimplements

  SlidingPaneLayout.PanelSlideListener {

 

 @Override

 protectedvoidonCreate(Bundle savedInstanceState) {

  initSlideBackClose();

  super.onCreate(savedInstanceState);

 }

 

 privatevoidinitSlideBackClose() {

  if(isSupportSwipeBack()) {

   SlidingPaneLayout slidingPaneLayout =newSlidingPaneLayout(this);

   // 通过反射改变mOverhangSize的值为0,

   // 这个mOverhangSize值为菜单到右边屏幕的最短距离,

   // 默认是32dp,现在给它改成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));

 

   // 左侧的透明视图

   View leftView =newView(this);

   leftView.setLayoutParams(newViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));

   slidingPaneLayout.addView(leftView,0);

 

   ViewGroup decorView = (ViewGroup) getWindow().getDecorView();

 

 

   // 右侧的内容视图

   ViewGroup decorChild = (ViewGroup) decorView.getChildAt(0);

   decorChild.setBackgroundColor(getResources()

     .getColor(android.R.color.white));

   decorView.removeView(decorChild);

   decorView.addView(slidingPaneLayout);

 

   // 为 SlidingPaneLayout 添加内容视图

   slidingPaneLayout.addView(decorChild,1);

  }

 }

 

 protectedbooleanisSupportSwipeBack() {

  returntrue;

 }

 

 @Override

 publicvoidonPanelSlide(View panel,floatslideOffset) {

 

 }

 

 @Override

 publicvoidonPanelOpened(View panel) {

  finish();

 }

 

 @Override

 publicvoidonPanelClosed(View panel) {

 

 }

}

 

activity 透明style:

 

 代码如下 复制代码

<resourcesxmlns:tools="http://www.bjxdzj.com/mgdz/tools">

 

 <!-- Base application theme. -->

 <stylename="AppTheme"parent="Theme.AppCompat.Light.DarkActionBar">

  <!-- Customize your theme here. -->

  <itemname="colorPrimary">@color/colorPrimary</item>

  <itemname="colorPrimaryDark">@color/colorPrimaryDark</item>

  <itemname="colorAccent">@color/colorAccent</item>

 </style>

 

 <stylename="DIY.SlideClose.Transparent.Theme"parent="AppTheme">

  <itemname="android:windowBackground">@android:color/transparent</item>

  <itemname="android:windowIsTranslucent">true</item>

  <itemname="android:windowAnimationStyle">@style/DIY.Animation.SlidingBack</item>

  <itemname="android:actionBarStyle">@style/DIYActionBar.Custom</item>

 </style>

 

 <stylename="DIYActionBar.Custom"parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">

  <itemname="displayOptions">showCustom</item>

  <itemname="android:background">@android:color/transparent</item>

  <itemname="background">@android:color/transparent</item>

  <itemname="android:displayOptions"tools:ignore="NewApi">showCustom</item>

  <itemname="android:height">?actionBarSize</item>

 </style>

 

 <stylename="DIY.Animation.SlidingBack"parent="@android:style/Animation.Activity">

  <itemname="android:activityOpenEnterAnimation">@anim/slide_in_right</item>

  <itemname="android:activityOpenExitAnimation">@anim/slide_out_right</item>

  <itemname="android:activityCloseEnterAnimation">@anim/slide_in_right</item>

  <itemname="android:activityCloseExitAnimation">@anim/slide_out_right</item>

  <itemname="android:wallpaperOpenEnterAnimation">@anim/slide_in_right</item>

  <itemname="android:wallpaperOpenExitAnimation">@anim/slide_out_right</item>

  <itemname="android:wallpaperCloseEnterAnimation">@anim/slide_in_right</item>

  <itemname="android:wallpaperCloseExitAnimation">@anim/slide_out_right</item>

  <itemname="android:wallpaperIntraOpenEnterAnimation">@anim/slide_in_right</item>

  <itemname="android:wallpaperIntraOpenExitAnimation">@anim/slide_out_right</item>

  <itemname="android:wallpaperIntraCloseEnterAnimation">@anim/slide_in_right</item>

  <itemname="android:wallpaperIntraCloseExitAnimation">@anim/slide_out_right</item>

 </style>

  

</resources>

 

没有了123 下一篇
上一页:没有了      下一页:android虚拟键盘弹出遮挡登陆按钮问题的解决方法
合作: 银河娱乐 真钱棋牌 mg电子