Xutils:https://github.com/wyouflf/xUtils
xUtils简介
· xUtils 包含了很多实用的android工具。
· xUtils 支持大文件上传,更全面的http请求协议支持(10种谓词),拥有更加灵活的ORM,更多的事件注解支持且不受混淆影响...
· xUitls 最低兼容android 2.2 (api level 8)
目前xUtils主要有四大模块:
·
DbUtils模块:
·
o android中的orm框架,一行代码就可以进行增删改查;
o 支持事务,默认关闭;
o 可通过注解自定义表名,列名,外键,唯一性约束,NOT NULL约束,CHECK约束等(需要混淆的时候请注解表名和列名);
o 支持绑定外键,保存实体时外键关联实体自动保存或更新;
o 自动加载外键关联实体,支持延时加载;
o 支持链式表达查询,更直观的查询语义,参考下面的介绍或sample中的例子。
·
ViewUtils模块:
·
o android中的ioc框架,完全注解方式就可以进行UI,资源和事件绑定;
o 新的事件绑定方式,使用混淆工具混淆后仍可正常工作;
o 目前支持常用的20种事件绑定,参见ViewCommonEventListener类和包com.lidroid.xutils.view.annotation.event。
·
HttpUtils模块:
·
o 支持同步,异步方式的请求;
o 支持大文件上传,上传大文件不会oom;
o 支持GET,POST,PUT,MOVE,COPY,DELETE,HEAD,OPTIONS,TRACE,CONNECT请求;
o 下载支持301/302重定向,支持设置是否根据Content-Disposition重命名下载的文件;
o 返回文本内容的请求(默认只启用了GET请求)支持缓存,可设置默认过期时间和针对当前请求的过期时间。
·
BitmapUtils模块:
·
o 加载bitmap的时候无需考虑bitmap加载过程中出现的oom和android容器快速滑动时候出现的图片错位等现象;
o 支持加载网络图片和本地图片;
o 内存管理使用lru算法,更好的管理bitmap内存;
o 可配置线程加载线程数量,缓存大小,缓存路径,加载显示动画等...
使用xUtils快速开发框架需要有以下权限:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
项目源码地址:http://square.github.io/picasso
依赖OkHttp:http://square.github.io/okhttp
使用说明和注意事项就去官网上自己查看
RadioGroup的设置:
<RadioGroup
android:id="@+id/radioGroup1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >
<RadioButton
android:id="@+id/radio0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
<span style="color:#FF0000;">
<span style="font-size:24px;">设置勾选框按钮为空</span></span>
android:button="@null"
android:checked="true"
android:gravity="center"
<span style="font-size:24px;">
<span style="color:#FF0000;">调用的是drawable里面的资源</span></span>
android:drawableTop="@drawable/ic_tab_artists"
android:text="团购" />
按钮的设置:
这是drawable的xml文件代码,用来实现点击状态和默认状态的切换:
</pre><pre name="code" class="html"><?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<span style="font-size:18px;color:#FF0000;">设置选中的状态</span>
<item android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/ic_tab_albums_selected"/>
<item android:state_checked="true" android:state_pressed="false" android:drawable="@drawable/ic_tab_albums_selected"/>
<span style="font-size:18px;color:#FF0000;">设置默认的状态</span>
<item android:drawable="@drawable/ic_tab_albums_unselected"/>
</selector>
主函数的代码:
public class MainActivity extends FragmentActivity {
<span style="color:#FF0000;">// 使用xutils注入bottom_bar</span>
@ViewInject(R.id.bottom_bar)
private RadioGroup bottom_bar;
@ViewInject(R.id.layout_content)
private FrameLayout layout_content;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
<span style="color:#FF0000;">// 依赖注入我们就不用一个一个地去findView</span>
ViewUtils.inject(this);
}
<span style="color:#FF0000;">// 进行注解,监听底部的bar的点击事件</span>
@OnCheckedChange({ R.id.bottom_bar })
public void onCheckedChanged(RadioGroup group, int checkedId) {
int index=0;
//通过选择的radiao来判断当前位置
switch(checkedId){
case R.id.radio0:
index=0;
break;
case R.id.radio1:
index=1;
break;
case R.id.radio2:
index=2;
break;
case R.id.radio3:
index=3;
break;
}
Fragment fragment=(Fragment) fragments.instantiateItem(layout_content, index);
fragments.setPrimaryItem(layout_content,0,fragment);
//提交
fragments.finishUpdate(layout_content);
}
<span style="color:#FF0000;">//重写restart方法,为了触发onCheckedChanged事件</span>
protected void onStart() {
super.onStart();
bottom_bar.check(R.id.radio0);
};
//为RadioGroup添加adapter
FragmentStatePagerAdapter fragments=new FragmentStatePagerAdapter(getSupportFragmentManager()) {
public int getCount() {
return 4;
}
public Fragment getItem(int arg0) {
//下面四个实例化的对象是我们创建的填充fragment布局的类
switch(arg0){
case 0:
return new FragmentIndex();
case 1:
return new FragmentNearby();
case 2:
return new FragmentMy();
case 3:
return new FragmentMore();
default:
return new FragmentIndex();
}
}
};
}
填充fragment的类的代码如下
public class FragmentIndex extends Fragment{
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view=LayoutInflater.from(getActivity()).inflate(R.layout.frag_index,null);
return view;
}
<span style="color:#FF0000;">//重写setMenuVisibility方法,防止发生重叠现象</span>
public void setMenuVisibility(boolean menuVisible) {
super.setMenuVisibility(menuVisible);
if(this.getView()!=null){
this.getView().setVisibility(menuVisible?View.VISIBLE:View.GONE);
}
}
}