SwipeBackLayou和Slider实现侧滑退出界面

SwipeBackLayout

引入库:compile 'me.imid.swipebacklayout.lib:library:1.1.0'

地址:https://github.com/ikew0ng/SwipeBackLayout

还有一个更加强大的Slider,地址:https://github.com/KobeKomi/Slider


这里主要写关于SwipeBackLayout简单使用

第一步:引入compile 'me.imid.swipebacklayout.lib:library:1.1.0'

第二步:直接在你要实现的Activity上继承SwipeBackActivity

public class SecondActivity extends SwipeBackActivity {
    private SwipeBackLayout swipeBackLayout;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.left_fragment);
        swipeBackLayout = getSwipeBackLayout();
        setSwipeBackEnable(true);//是否允许滑动退出
        swipeBackLayout.setEdgeTrackingEnabled(SwipeBackLayout.EDGE_LEFT);//设置滑动方向(EDGE_LEFT, EDGE_RIGHT, EDGE_ALL, EDGE_BOTTOM)
        swipeBackLayout.setEdgeSize(200);//设置滑动范围(0~200),不能实现全屏滑动。

    }
}

但是到这里并没有结束,网上有很多说法滑动时界面时,底部黑屏。多方查证,应该是androdi版本造成的。我个人用的android 7.0,并没有出现黑屏情况。如果出现黑屏就需要添加一下代码。

给你滑动界面添加半透明

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

给主界面添加

<item name="android:windowIsTranslucent">false</item>


目前 ,我自己想实现一个滑动屏幕任意位置,Activity退出。所以这里就用第二个框架,详细用法如下地址

https://github.com/KobeKomi/Slider/blob/master/README_CN.md

public class SecondActivity extends SliderActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.left_fragment);
        initView();
    }

    private void initView() {
        mConfig.setPosition(SliderPosition.LEFT);//设置滑动退出方向
        mConfig.setEdgeOnly(false);//设置是否允许滑动屏幕任意位置退出
        iSlider.setConfig(mConfig);

    }
}
这个框架可以说是加强版的,里面还有很多功能。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
USAGE 1.Currently supported Activity, Fragment, DialogFragment,Dilaog and View. 2.By following simple operation, it may have a sliding function. by SliderUtils.attach* public class SampleActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_slider); SliderUtils.attachActivity(this, mConfig); } } or by extends: public class ExtendsActivity extends SliderActivity { } or by xml: <com.komi.slider.Slider xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:slider="http://schemas.android.com/apk/res-auto" android:id="@+id/xml_slider_layout" android:layout_width="match_parent" android:layout_height="match_parent" slider:edgeOnly="false" slider:position="all"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:text="I CAN SLIDE NOW!" android:textSize="23sp" /> </com.komi.slider.Slider> Note: activity of manifest need to override the configured theme: android: windowIsTranslucent, otherwise slide open the background is black. <style name="ActivityTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <item name="android:windowIsTranslucent">true</item> </style> If the device is greater than the version of android L, you can use the following method instead: SliderUtils.attachUi(this, null); Utils.convertActivityToTranslucent activity) If extends SliderFragment, you need to pay attention to is: SliderFragment onCreateView function have been final overwritten, so another abstract methods to achieve creatingView and returns the layout of inflate objects. public class ExtendsFragment extends SliderFragment { @Override public View creatingView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return inflater.inflate(R.layout.fragment_entends, container, false); } } or by SliderUtils public class SampleFragment extends Fragment { private ISlider iSlider; private View rootView; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { rootView = inflater.inflate(R.layout.fragment_sample, container, false); SliderUtils.attachFragment(this, rootView,null) return iSlider.getSliderView(); } } DialogFragment: extends SliderDialogFragment or like this: public class SlidabelDialogFragment extends DialogFragment { protected ISlider iSlider; @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); iSlider = SliderUtils.attachDialog(getActivity(),getDialog(),mConfig); } } For more details, please refer to the code DEPENDENCIES dependencies{ compile 'com.komi.slider:slider:0.4.0' } ISSUES 1.Welcome to the Issues and refine the project, if you like, please click on the star, later will expand more useful features! 2.This project extends from SwipeBackLayout and Slidr AUTHOR KobeKomi
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值