SwipeBackActivity的另一种方法(二)
来源:互联网 发布:网络作家系列小说 编辑:程序博客网 时间:2024/05/16 03:25
摘要:关于SwipeBackActivity,主要注意以下几种情况:
1.引入 compile ‘com.github.liuguangqiang.swipeback:library:1.0.2@aar’
2.将app的主题设置加入 true
–这样主题就可以使透明的,不能用默认的主题;使用默认背景就是黑屏了,这个属性就是设置防止黑屏的。
关于阻止黑屏可查看:http://blog.csdn.net/fancylovejava/article/details/39643449
3.这个侧滑关闭页面的方法,同时这个三方的包的出处地址是:https://github.com/liuguangqiang/SwipeBack(里面有完整项目),感谢
4.滑动关闭有4种形式,上下左右,在下面已经列举了
5.已经就遇到了,今天终于不是仅仅看人家的代码了,自己把代码写出来真的很好,印象也加深了;多加练习肯定会不一样的,加油。
6.同时引入了作者的另一个加载圆形进度条的库:compile ‘com.github.liuguangqiang.prettyprogressbar:library:+’;这个也不错
因为我之前写了一篇SwipeBack的用法文章(详情请点击:http://blog.csdn.net/yangjianbo456/article/details/51509635,但是那个的三种方向是:
/*
* 滑动关闭当前页面的方向有四种形式
* 1.SwipeBackLayout.EDGE_RIGHT 右边关闭页面
* 2.SwipeBackLayout.EDGE_LEFT 左边关闭页面
* 3.SwipeBackLayout.EDGE_BOTTOM 底部关闭页面
* 4.SwipeBackLayout.EDGE_ALL 以上三种形式关闭页面
*/
下面展示代码:
主要代码:
package com.yjbo.testswipeback2;import android.os.Bundle;import android.view.View;import android.widget.TextView;import com.liuguangqiang.swipeback.SwipeBackLayout;import com.yjbo.testswipeback2.swipeUtil.SwipeBackActivity;import butterknife.Bind;import butterknife.ButterKnife;import butterknife.OnClick;public class SecondActivity extends SwipeBackActivity { @Bind(R.id.txt_show_tip) TextView txtShowTip; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_second); ButterKnife.bind(this); setDragEdge(SwipeBackLayout.DragEdge.LEFT); } @OnClick({R.id.txt_right, R.id.txt_left, R.id.txt_buttom, R.id.txt_top}) public void onClick(View view) { switch (view.getId()) { case R.id.txt_right: changeShowTxt(0); break; case R.id.txt_left: changeShowTxt(1); break; case R.id.txt_buttom: changeShowTxt(2); break; case R.id.txt_top: changeShowTxt(3); break; } } private void changeShowTxt(int i) { switch (i) { case 0: setDragEdge(SwipeBackLayout.DragEdge.LEFT); txtShowTip.setText("当前是向右滑动返回"); break; case 1: setDragEdge(SwipeBackLayout.DragEdge.RIGHT); txtShowTip.setText("当前是向左滑动返回"); break; case 2: setDragEdge(SwipeBackLayout.DragEdge.TOP); txtShowTip.setText("当前是向下滑动返回"); break; case 3: setDragEdge(SwipeBackLayout.DragEdge.BOTTOM); txtShowTip.setText("当前是向上滑动返回"); break; } }}
xml配置声明:
<application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".SecondActivity" android:theme="@style/Theme.Swipe.Back"></activity> </application>
样式:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <item name="colorPrimary">#db4336</item> <item name="colorPrimaryDark">#b63120</item> </style> <style name="Theme.Swipe.Back" parent="Theme.AppCompat.Light.NoActionBar"> <item name="android:windowIsTranslucent">true</item> <item name="android:windowBackground">@android:color/transparent</item> <item name="windowActionBar">false</item> <item name="android:windowNoTitle">true</item> </style>
这里面还有一个强大的功能:
(引用了圆形进度条的第三方包: compile ‘com.github.liuguangqiang.prettyprogressbar:library:+’)
这里调用了:
swipeBackLayout.setOnPullToBackListener(new SwipeBackLayout.SwipeBackListener() { @Override public void onViewPositionChanged(float fractionAnchor, float fractionScreen) { progressBar.setProgress((int) (progressBar.getMax() * fractionAnchor)); txt_progress.setText((progressBar.getMax() * fractionAnchor)+""); } });
完整代码:
package com.liuguangqiang.swiplebacksample;import android.app.Activity;import android.media.Image;import android.os.Bundle;import android.view.View;import android.widget.ImageView;import android.widget.TextView;import com.liuguangqiang.progressbar.CircleProgressBar;import com.liuguangqiang.swipeback.SwipeBackLayout;/** * Created by Eric on 15/2/27. */public class DemoActivity extends Activity { private CircleProgressBar progressBar; private SwipeBackLayout swipeBackLayout; private ImageView image_back; private TextView txt_progress; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_demo); initViews(); } private void initViews() { progressBar = (CircleProgressBar) findViewById(R.id.progressbar1); txt_progress = (TextView) findViewById(R.id.txt_progress); image_back = (ImageView) findViewById(R.id.image_back); image_back.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { finish(); } }); swipeBackLayout = (SwipeBackLayout) findViewById(R.id.swipe_layout); swipeBackLayout.setEnableFlingBack(false); swipeBackLayout.setOnPullToBackListener(new SwipeBackLayout.SwipeBackListener() { @Override public void onViewPositionChanged(float fractionAnchor, float fractionScreen) { progressBar.setProgress((int) (progressBar.getMax() * fractionAnchor)); txt_progress.setText((progressBar.getMax() * fractionAnchor)+""); } }); }}
xml文件:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:pb="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/darker_gray"> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:layout_marginTop="10dp"> <com.liuguangqiang.progressbar.CircleProgressBar android:id="@+id/progressbar1" android:layout_width="45dp" android:layout_height="45dp" pb:background_color="@android:color/transparent" pb:progress_color="@android:color/white" android:layout_alignParentLeft="true" pb:stroke_width="2dp" /> <ImageView android:id="@+id/image_back" android:layout_width="25dp" android:layout_height="25dp" android:layout_alignParentLeft="true" android:layout_marginLeft="10dp" android:layout_centerInParent="true" android:background="@drawable/ic_action_close_common" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:text="显示已经下拉的进度" android:id="@+id/txt_progress" android:layout_centerVertical="true" android:layout_alignParentRight="true"/> </RelativeLayout> <com.liuguangqiang.swipeback.SwipeBackLayout android:id="@+id/swipe_layout" android:layout_width="match_parent" android:layout_height="match_parent"> <RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <ImageView android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_centerInParent="true" android:layout_marginBottom="50dp" android:layout_marginLeft="16dp" android:layout_marginRight="16dp" android:layout_marginTop="100dp" android:background="@drawable/test2" /> </RelativeLayout> </com.liuguangqiang.swipeback.SwipeBackLayout></RelativeLayout>
http://download.csdn.net/detail/yangjianbo456/9547313demo里面没有增加这个功能,需要查看的请查看原创作者的github源码,在此也感谢原创作者。
这里有个升级版,(2016年6月13日23:27:12)是不需要依赖第三方的,下载源码http://download.csdn.net/detail/yangjianbo456/9548587
- SwipeBackActivity的另一种方法(二)
- SwipeBackActivity 的使用
- 高仿微信的滑动返回SwipeBackActivity
- 学习工作流的另一种方法
- 调用方法的另一种方式
- 调用方法的另一种方式
- 控制小数位的另一种方法
- 另一种数据导出的方法
- 学习工作流的另一种方法
- 锁定表格的另一种方法。
- 获得对象的另一种方法
- 动态XtraReports的另一种方法
- 另一种注释代码的方法.
- 表达式求值的另一种方法
- 数组统计分析的另一种方法
- 定时器的另一种初始化方法
- 布局填充的另一种方法
- 防御csrf的另一种方法
- ios中设置app音效音效和震动
- storm中初始化类
- 使用数据库保存session的方法
- 日志6.12
- 易宝支付开发实现
- SwipeBackActivity的另一种方法(二)
- Qt 4.7.2编译过程的简要记录
- JDBC学习
- laravel的基础学习(三)
- android framework重要的服务
- 航电 2041 超级楼梯
- CocoaPods 安装 使用
- C++复习4.笔试复习
- Android开发中使用fastJSON将json格式的数据快速解析生成实体类并附上实体类生成器