Android仿微信activity滑动关闭效果-创新互联

Android仿微信activity滑动关闭功能

十多年的滕州网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。成都全网营销的优势是能够根据用户设备显示端的尺寸不同,自动调整滕州建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。成都创新互联公司从事“滕州网站设计”,“滕州网站推广”以来,每个客户项目都认真落实执行。

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) {

 }
}


网页题目:Android仿微信activity滑动关闭效果-创新互联
转载注明:http://cdiso.cn/article/dsjisj.html

其他资讯