1、Android新增的百分比布局
android.support.percent.PercentFrameLayout
在build.gradle下添加依赖包
compile 'com.android.support:percent:22.2.0'
2、LitePal开源数据库框架
3、关于ListView的优化
在Adapter的getView(int position,View convertView,ViewGroup parent)
方法中对于ListView的优化点主要是加载xml文件以及xml文件的组件加载处性能优化。
优化代码如下所示:
判断convertView是否为null,如果为null那么就通过LayoutInflater.from去加载布局文件,如果不为null则不用浪费性能重新加载xml文件,同样通过findViewWithTag或者findViewById的方式获取组件依旧会出现浪费性能的情况,所以这里通过myHolder.textView这样的方式获取组件就会提高ListView的加载性能,经过这两种方式就可以大大的提供ListView的性能了。
public View getView(final int position, View convertView, ViewGroup parent) {
MyHolder myHolder = null;
if (convertView == null) {
convertView = LayoutInflater.from(mContext).inflate(SDKUtils.getResLayoutId(mContext, "user_item"), null);
myHolder = new MyHolder();
myHolder.textView = (TextView) convertView.findViewWithTag("account_textview");
myHolder.imageView = (ImageView) convertView.findViewWithTag("account_icon");
myHolder.delButton = (ImageView) convertView.findViewWithTag("account_del");
convertView.setTag(myHolder);
convertView.setLayoutParams(new AbsListView.LayoutParams(LayoutParams.MATCH_PARENT,
SDKUtils.getDimenValue(mContext, "user_item_height")));
if (currentAccount.getText().toString().equals(list.get(position).getUserName())) {
myHolder.imageView.setBackgroundResource(SDKUtils.getDrawableId(mContext, "sdk_select_account"));
} else {
myHolder.imageView.setBackgroundColor(Color.TRANSPARENT);
}
} else {
myHolder = (MyHolder) convertView.getTag();
}
myHolder.textView.setText(list.get(position).getUserName());
myHolder.delButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
SDKDBManager.getInstance().creatDB(mContext);
SDKDBManager.getInstance().deleteAccount(list.get(position).getUserName());
list.remove(position);
notifyDataSetChanged();
currentAccount.setText("");
}
});
return convertView;
}
class MyHolder {
public ImageView imageView;
public TextView textView;
public ImageView delButton;
}
android.support.percent.PercentFrameLayout
在build.gradle下添加依赖包
compile 'com.android.support:percent:22.2.0'
2、LitePal开源数据库框架
3、关于ListView的优化
在Adapter的getView(int position,View convertView,ViewGroup parent)
方法中对于ListView的优化点主要是加载xml文件以及xml文件的组件加载处性能优化。
优化代码如下所示:
判断convertView是否为null,如果为null那么就通过LayoutInflater.from去加载布局文件,如果不为null则不用浪费性能重新加载xml文件,同样通过findViewWithTag或者findViewById的方式获取组件依旧会出现浪费性能的情况,所以这里通过myHolder.textView这样的方式获取组件就会提高ListView的加载性能,经过这两种方式就可以大大的提供ListView的性能了。
public View getView(final int position, View convertView, ViewGroup parent) {
MyHolder myHolder = null;
if (convertView == null) {
convertView = LayoutInflater.from(mContext).inflate(SDKUtils.getResLayoutId(mContext, "user_item"), null);
myHolder = new MyHolder();
myHolder.textView = (TextView) convertView.findViewWithTag("account_textview");
myHolder.imageView = (ImageView) convertView.findViewWithTag("account_icon");
myHolder.delButton = (ImageView) convertView.findViewWithTag("account_del");
convertView.setTag(myHolder);
convertView.setLayoutParams(new AbsListView.LayoutParams(LayoutParams.MATCH_PARENT,
SDKUtils.getDimenValue(mContext, "user_item_height")));
if (currentAccount.getText().toString().equals(list.get(position).getUserName())) {
myHolder.imageView.setBackgroundResource(SDKUtils.getDrawableId(mContext, "sdk_select_account"));
} else {
myHolder.imageView.setBackgroundColor(Color.TRANSPARENT);
}
} else {
myHolder = (MyHolder) convertView.getTag();
}
myHolder.textView.setText(list.get(position).getUserName());
myHolder.delButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
SDKDBManager.getInstance().creatDB(mContext);
SDKDBManager.getInstance().deleteAccount(list.get(position).getUserName());
list.remove(position);
notifyDataSetChanged();
currentAccount.setText("");
}
});
return convertView;
}
class MyHolder {
public ImageView imageView;
public TextView textView;
public ImageView delButton;
}