栏目分类:
子分类:
返回
文库吧用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
文库吧 > IT > 软件开发 > 移动开发 > Android

Android仿微信activity滑动关闭效果

Android 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Android仿微信activity滑动关闭效果

Android仿微信activity滑动关闭功能

1.利用具体利用v4包下的slidingPaneLayout实现透明的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值为菜单到右边屏幕的最短距离,
   // 默认是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 = 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();


   // 右侧的内容视图
   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);
  }
 }

 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:



 
 
  
  @color/colorPrimary
  @color/colorPrimaryDark
  @color/colorAccent
 

 
  @android:color/transparent
  true
  @style/DIY.Animation.SlidingBack
  @style/DIYActionBar.Custom
 

 
  showCustom
  @android:color/transparent
  @android:color/transparent
  showCustom
  ?actionBarSize
 

 
  @anim/slide_in_right
  @anim/slide_out_right
  @anim/slide_in_right
  @anim/slide_out_right
  @anim/slide_in_right
  @anim/slide_out_right
  @anim/slide_in_right
  @anim/slide_out_right
  @anim/slide_in_right
  @anim/slide_out_right
  @anim/slide_in_right
  @anim/slide_out_right
 
 

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

转载请注明:文章转载自 www.wk8.com.cn
本文地址:https://www.wk8.com.cn/it/160047.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 wk8.com.cn

ICP备案号:晋ICP备2021003244-6号