Tips
来源:互联网 发布:网络大电影如何运作 编辑:程序博客网 时间:2024/05/22 23:59
防止在当前Activity中截屏
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //防止当前activity内截屏 getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);}
查看当前Activity和包名,方便调试
安装TopActivity.apk
wireshark抓包找不到网卡
1、命令提示符-右键-以管理员身份运行
2、输入net start npf回车,提示NetGroup Packet Filter Driver 服务已经启动成功。
3、重新打开wireshark或者刷新网卡设备即可发现网卡。
实现圆角进度对话框
效果,类似于GooglePlay进度效果:
1、创建对话框
Dialog dialog = new Dialog(this, R.style.mydialog);//R.style.mydialog为样式,用于实现圆角效果 dialog.setContentView(R.layout.dialog); dialog.show();
2、定义样式R.style.mydialog
<style name="mydialog" parent="android:style/Theme.Dialog"> <!-- 背景透明 --> <item name="android:windowBackground">@android:color/transparent</item> <!-- 没有标题 --> <item name="android:windowNoTitle">true</item> <!-- 背景模糊 --> <item name="android:backgroundDimEnabled">true</item> </style>
3、定义对话框布局R.layout.dialog
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/shape" android:gravity="center" android:orientation="vertical" android:paddingBottom="10dp" android:paddingLeft="40dp" android:paddingRight="40dp" android:paddingTop="10dp"> <ProgressBar android:layout_width="wrap_content" android:layout_height="wrap_content" android:indeterminateDrawable="@drawable/layer_list_progress"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="8dp" android:text="努力加载中..." android:textColor="#fff" android:textSize="16sp"/></LinearLayout>//背景的shape<?xml version="1.0" encoding="utf-8"?><shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="@android:color/darker_gray" /> <corners android:radius="10dp" /></shape>//进度条的drawable<?xml version="1.0" encoding="utf-8"?><layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item> <rotate android:drawable="@drawable/spinner_big_inner" android:fromDegrees="0" android:pivotX="50%" android:pivotY="50%" android:toDegrees="720" /> </item> <item> <rotate android:drawable="@drawable/spinner_big_outer" android:fromDegrees="360" android:pivotX="50%" android:pivotY="50%" android:toDegrees="0" /> </item></layer-list>
TextView设置圆形背景效果
效果如图:
private void init() { // A Drawable with a color gradient for buttons, backgrounds, etc. GradientDrawable gradientDrawable = new GradientDrawable(); gradientDrawable.setSize(200,200);//大小 gradientDrawable.setCornerRadius(100);//圆角半径 gradientDrawable.setColor(Color.RED);//颜色可传 ImageView imageView = (ImageView) findViewById(R.id.iv); imageView.setBackground(gradientDrawable); }
FragmentStatePagerAdapter Vs FragmentPagerAdapter
/**
* Implementation of {@link android.support.v4.view.PagerAdapter} that
* uses a {@link Fragment} to manage each page. This class also handles
* saving and restoring of fragment’s state.
*
*
This version of the pager is more useful when there are a large number
* of pages, working more like a list view. When pages are not visible to
* the user, their entire fragment may be destroyed, only keeping the saved
* state of that fragment. This allows the pager to hold on to much less
* memory associated with each visited page as compared to
* {@link FragmentPagerAdapter} at the cost of potentially more overhead when
* switching between pages.
*/
/**
* Implementation of {@link android.support.v4.view.PagerAdapter} that
* represents each page as a {@link Fragment} that is persistently
* kept in the fragment manager as long as the user can return to the page.
*
*
This version of the pager is best for use when there are a handful of
* typically more static fragments to be paged through, such as a set of tabs.
* The fragment of each page the user visits will be kept in memory, though its
* view hierarchy may be destroyed when not visible. This can result in using
* a significant amount of memory since fragment instances can hold on to an
* arbitrary amount of state. For larger sets of pages, consider
*{@link FragmentStatePagerAdapter}.
*/
总结:
《1》二者都是PagerAdapter的实现,用于维护ViewPager中的Ffragment
《2》FragmentStatePagerAdapter 处理Fragment状态的保存和恢复,后者只要用户还能够返回该Fragment,那么就会将其保留在Fragment Manager中。
《3》FragmentStatePagerAdapter 其机制类似于ListView,当页面不可见时,整个Fragment可能被销毁,而只保留其状态,因此内存更友好。
FragmentPagerAdapter而言,尽管View可能会被销毁,但是整个Fragment会将Fragment完全保留在内存中。
因此,前者更适合于大量的Fragment使用时;后者则更多是用于处理静态Fragment。
因此,对于Fragment的状态及生命周期不敏感时,会推荐使用前者。
- Tips
- Tips
- Tips
- Tips
- > tips
- Tips
- Tips
- Tips
- Tips
- Tips
- Tips
- tips
- tips
- tips
- TIPS
- TIPS
- tips
- Tips
- 7种排序算法
- 【POJ 2182 Lost Cows】+ 线段树
- HDU 2504
- Hibernate5.2.4环境搭建
- 平衡二叉树
- Tips
- java 内存泄漏
- Toolbar的使用
- git学习-上传项目
- 协会批判日记
- 野指针的危害以及数组指针和指针数组区别
- OpenSSL学习笔记-简介
- innodb所有文件分析
- [阅读笔记]Modern C++ Programming with Test-Driven Develpment chp3