常用的第三方库
来源:互联网 发布:苹果编程语言swift 编辑:程序博客网 时间:2024/04/27 20:45
1.UI库
PagerSlidingTabStrip————ViewPager的标题导航方便实用的viewPager标题的分页导航条
引入依赖地址compile 'com.jpardogo.materialtabstrip:library:1.0.6'
PagerSlidingTabStrip——GitHub
在xml文件中增加的属性值
pstsIndicatorColor
可以滑动的指示器的颜色pstsUnderlineColor
view底部的线条的颜色pstsIndicatorHeight
指示器的高度pstsDividerPadding
选项标题之间的分隔线的上下边距pstsTabPaddingLeftRight
选项标题的左右边距pstsScrollOffset
滚动所选标题的偏移量pstsTabBackground
选项标题的背京图,应该设为一个StateListDrawablepstsShoudeExpand
为true则每个选项标题的宽度相等,默认falsepstsTextAllCaps
为true则每个选项标题的字母都为大写,默认为true
和ViewPager联合起来用,在xml中放在ViewPager控件的上面
//通常自定的MyViewPagerAdapter都是继承于FragmentPagerAdapter,需要重写getPageTitle方法viewPager.setAdapter(new MyViewPagerAdapter());// 在activity的onCreate(或者fragment的onCreateView)方法中,将PagerSlidingTabStrip绑定到ViewPager上pagerSlidingTabStrip.setViewPager(viewPager);
若需要对选项改变事件监听则
pagerSlidingTabStrip.setOnPageChangeListener(mPageChangeListener);
TabLayout————ViewPager的标题导航栏
android官方Support Design包推出的分页标题导航
引入依赖compile 'com.android.support:design:23.3.0'
TabLayout官方说明
在xml中增加的属性
app:tabBackground:
标题的背景app:tabContentStart:
标题在Y方向上的位置app:tabGravity:
标题的分布位置(当模式为左右滑动标题时有效,标题在标题栏中的位置是center还是fill)app:tabIndicatorColor:
可以滑动的指示器的颜色app:tabIndicatorHeight:
可以滑动的指示器的高度app:tabMaxWidth:
标题最大宽度app:tabMinWidth:
标题最小宽度app:tabMode:
标题的类型 有两种(Mode_Scrollable左右滑动只显示一栏的标题;Mode_Fixed固定在屏幕上显示全部标题)app:tabPadding:
标题的边距app:tabPaddingBotton:
标题下边距app:tabPaddingEnd:
标题右边距app:tabPaddingStart:
标题左边距app:tabPaddingTop:
标题上边距app:tabSelectedTextColor:
被选择标题的字体颜色app:tabTextAppearance:
标题的字体属性app:tabTextColor:
标题的字体颜色
TabLayout中可以嵌套TabItem类(标题类)
<android.support.design.widget.TabLayout android:layout_width="match_parent" android:layout_height="56dp"> <android.support.design.widget.TabItem android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="tab1"/> <android.support.design.widget.TabItem android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Tab2"/> </android.support.design.widget.TabLayout>
TabItem相关XML属性
- android:icon:
标题的图标
- android:layout:
标题自定义的布局view
- android:text:
标题文字
和Viewpager联合使用,在xml文件中放在ViewPager的上面或者下面
//在代码中将两者联合起来viewpager.setAdapter(new MyPagerAdapter());tabLayout.setUpWithViewPager(viewPager);
Demo:
//在XML中设置布局<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.example.wendy.coordinatorlayouttest.ThirdActivity"> <android.support.v4.view.ViewPager android:id="@+id/vp_third" android:layout_width="match_parent" android:layout_height="20dp" android:layout_above="@+id/tab_third" android:layout_alignParentTop="true"> </android.support.v4.view.ViewPager> <android.support.design.widget.TabLayout android:id="@+id/tab_third" android:layout_width="match_parent" android:layout_height="56dp" android:layout_alignParentBottom="true" app:tabBackground="@color/colorPrimary" app:tabGravity="fill" app:tabIndicatorHeight="0dp" app:tabMode="fixed"/></RelativeLayout>//在代码中public class ThirdActivity extends AppCompatActivity { private List<String> tabs = new ArrayList<>(); private ViewPager viewPager; private TabLayout tabLayout; private int[] icons = {R.drawable.icon, R.drawable.icon, R.drawable.icon, R.drawable.icon};//这里的icons全都指向drawable中的state-selector-drawable文件 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_third); initViewPager(); initTab(); }//初始化viewpager并设置自定义的fragmentAdapter private void initViewPager() { for (int i = 0; i < 4; i++) { tabs.add("Tab" + (i + 1)); } APagerAdapter aPagerAdapter = new APagerAdapter(getSupportFragmentManager()); viewPager = findViewById(R.id.vp_third); viewPager.setAdapter(aPagerAdapter); }//初始化TabLayout private void initTab() { tabLayout = findViewById(R.id.tab_third); tabLayout.setupWithViewPager(viewPager);//将tabLayout与viewPager绑定 for (int i = 0; i < tabs.size(); i++) { TabLayout.Tab tab = tabLayout.getTabAt(i);//获得绑定之后的标签 if (tab != null) { tab.setCustomView(R.layout.tab_item);//给每一个标签设置自定义的视图 View view = tab.getCustomView(); TextView textView = view.findViewById(R.id.tv_tab);//设置标签视图的内容,注意textView的textColor属性可以设置为state-selector-color类型 textView.setText("Tab" + i); ImageView imageView = view.findViewById(R.id.iv_tab); imageView.setImageResource(icons[i]);//imageResource可以指向state-selector-Drawable } } } class APagerAdapter extends FragmentPagerAdapter { public APagerAdapter(FragmentManager fm) { super(fm); } @Override public Fragment getItem(int position) { switch (position) { case 0: return TabFragment.getInstance(position); default: return new SecondFragment(); } } @Override public int getCount() { return tabs.size(); } @Override public CharSequence getPageTitle(int position) { return tabs.get(position); } }}//R.layout.tab_item布局格式<?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="match_parent" android:orientation="vertical" android:padding="6dp" android:weightSum="4"> <ImageView android:id="@+id/iv_tab" android:layout_width="wrap_content" android:layout_height="0dp" android:layout_gravity="center" android:layout_weight="3" android:scaleType="centerInside" android:src="@mipmap/ic_launcher_foreground"/> <TextView android:id="@+id/tv_tab" android:layout_width="wrap_content" android:layout_height="0dp" android:layout_alignBottom="@+id/iv_tab" android:layout_centerHorizontal="true" android:layout_gravity="center" android:layout_weight="1" android:text="通讯录" android:textColor="@color/textcolor"//指向res/color/中的state-selector-color文件 android:textIsSelectable="true"//设置text为可以选择的模式 android:textSize="10dp"/></LinearLayout>
2.工具库
是一个简单的 key-value 数据储存库,操作数据库只需一行代码 , 能存任何数据类型 使用: AES
加密,能选择使用SharedPreferences 、 SQLite、file作为底层储存方式,Gson解析
Hawk—GitHub
添加进项目中:在build.gradle(app)中
repositories { // ... maven { url "https://jitpack.io" } } dependencies { compile 'com.github.orhanobut:hawk:1.21' }
初始化Hawk
;//初始化只需要一次就行了 放在你最开始执行的activity里面 或者 applicationHawk.init(this) .setEncryptionMethod(HawkBuilder.EncryptionMethod.MEDIUM) ;//使用中等安全级别,不需要设置密码 ;(HawkBuilder.EncryptionMethod.HIGHEST)使用高安全级别,需要设置密码 ;//.setPassword("password") //高安全级别时,设置密码 .setStorage(HawkBuilder.newSqliteStorage(this)) ;//使用SQLite储存数据 (HawkBuilder.newSharedPrefStorage(this)) ;//也可以使用sharedPreference来储存数据 .setLogLevel(LogLevel.FULL) .build();
使用Hawk
//存储数据Hawk.put(key, obj); // 返回值为boolean,数据储存 Hawk.chain() //使用链接一次可以储存多个数据 .put(KEY_LIST, List<T>) .put(KEY_ANOTHER,"test") .commit(); //取读数据Hawk.get(key, T);//T是为null时设置的默认值//移除数据Hawk.remove(key1...key2) //可以一次移除多个数据//是否包含某个Keyboolean boo = Hawk.contains(key)
LeakCanary————内存泄漏检测库
可视化的内存泄露检测分析工具
LeakCanary—GitHub
debug版本会自动跳出一个关联的图标,当检测到内存泄漏时会自动发出notification
添加进项目 build.gradle(app)
dependencies { debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1' releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1' testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1' } // 其中releaseCompile和testCompile这两个的依赖属于NOOP操作。(NOOP,即No Operation Performed,无操作指令。常用的编译器技术会检测无操作指令并出于优化的目的将无操作指令剔除。)因而,只要配置好releaseCompile和testCompile的依赖,就无需担心对外版本的性能问题了。
初始化及使用
//初始化public class MyApplication extends Application { private static RefWatcher sRefWatcher; @Override public void onCreate() { super.onCreate(); sRefWatcher = LeakCanary.install(this);//默认是监测所有activity的内存泄漏情况 } public static RefWatcher getRefWatcher() { return sRefWatcher; }}//使用方法//默认是检测所有的activity,需要监控某个可能存在内存泄露的对象时,放在对象需要被释放的时候,如fragment的onDestory()方法中MyApplication.getRefWatcher().watch(sLeaky);
Android-Iconics
通过这个库可以导入支持的矢量图标,随时更改图标的color,size,background,padding,position等属性, 使用IconicsDrawable,不需要在多种分辨率下 建立多个drawable(1)添加到项目中
compile “com.mikepenz:iconics-core:2.9.1@aar”
Glide
非常方便的图片加载库,可以通过 uri,bitmap,resid,file,等各种方式加载包括gif,video,bitmap等格式的图片同时设置显示的动画Glide—GitHub
- 常用的第三方库
- 常用的第三方库
- 常用的第三方库
- 常用第三方库
- 常用第三方库
- 常用的几个第三方 Python 库
- 常用的几个第三方 Python 库
- 常用的几个第三方 Python 库
- iOS常用的第三方库
- 常用的几个第三方 Python 库
- python常用的第三方库
- iOS开发常用的第三方库
- 关于常用第三方库的混淆
- iOSk开发常用的第三方库
- 常用的iOS第三方库
- ios开发常用的第三方库
- iOS 开发常用的第三方库
- ios 一些常用的第三方库
- 【马仔创业感悟】什么是初创公司
- hdu 1789 贪心 优先队列
- 权限管理数据库设计思路
- One or more listeners failed to start. Full details will be found in the appropriate container log
- HTML5性能优化(三)
- 常用的第三方库
- PTA自测-3 数组元素循环右移问题
- break和continue的区别
- 瀑布式开发方法--《启示录》
- Nginx 配置文件 nginx.conf 详解
- window案例
- MongoDB
- hdu 3018 欧拉路
- HIVE数据表的导入导出