1.使用Glide加载图片
Glide.with(mContext).load(bean.getLogo())
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.color.white)
// .animate(R.anim.zoom_in)
.crossFade()
.error(R.drawable.default_load)
.into(holder.nimg_icon);
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
Glide.with(GoldCoinActivity.this).resumeRequests();
} else {
Glide.with(GoldCoinActivity.this).pauseRequests();
}
Glide.with(mContext).load(item.getUserAvatar())
.crossFade().into((ImageView) helper.getView(R.id.iv));
2.TextView设置Html标签文本
tv_ver.setText(Html.fromHtml("¥ "));
3.ListView的条目加载动画
//动画加载
private void setAnimation(View viewToAnimate, int position) {
if (position > lastPosition) {
Animation animation = AnimationUtils.loadAnimation(viewToAnimate.getContext(), R
.anim.item_bottom_in);
viewToAnimate.startAnimation(animation);
lastPosition = position;
}
}
4.PopuWindow重写返回键
contentview.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
popupWindow.dismiss();
return true;
}
return false;
}
});
5.view需要响应模拟点击的时候调用performClick()方法即可
6.等待子线程结束
try {
thread.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
7.动态添加TextView
for (int i = 0; i < contentBean.getPersonal_mark().size(); i++) {
View convertView = LayoutInflater.from(this).inflate(
R.layout.item_guide_detail_tag, null);
TextView textView = (TextView) convertView.findViewById(R.id.tv_tag);
textView.setText(contentBean.getPersonal_mark().get(i));
ll_like.addView(convertView);
}
8.复写键盘搜索
cet_content.setOnEditorActionListener(mOnEditorActionListener);
/**
* 修改的键盘搜索按钮点击事件
*/
private TextView.OnEditorActionListener mOnEditorActionListener=new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
((InputMethodManager) cet_content.getContext().getSystemService(Context.INPUT_METHOD_SERVICE))
.hideSoftInputFromWindow(
BrandShopsHotSearchActivity.this.getCurrentFocus().getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);
if (TextUtils.isEmpty(cet_content.getText().toString().trim())) {
ToastUtil.show(BrandShopsHotSearchActivity.this, "搜索内容不能为空!");
return true;
}
String key = cet_content.getText().toString().trim();
BrandShopsActivity.activities.get(0).finish();
BrandShopsActivity.startAction(BrandShopsHotSearchActivity.this, key);
cet_content.setText("");
finish();
return true;
}
return false;
}
};
9.给TextView动态设置图片
Drawable drawable = getResources().getDrawable(R.mipmap.icon_arrow_down_more);
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
tv_hotscenic.setCompoundDrawables(null, null, drawable, null);
10.利用广播机制管理Activity
/**
* 退出广播对应的ACTION
*/
public final static String INIENT_FINISH = "com.allfinish.method.finish";
/**
* 初始化退出广播
*/
public void initFinishReceiver() {
IntentFilter filter = new IntentFilter();
filter.addAction(INIENT_FINISH);
registerReceiver(mFinishReceiver, filter);
}
/**
* 监听是否退出的广播
*/
public BroadcastReceiver mFinishReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (INIENT_FINISH.equals(intent.getAction())) {
finish();
}
}
};
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
unregisterReceiver(mFinishReceiver);
super.onDestroy();
}
/**
* 发送广播退出多个Activity
*/
private void sendFinish() {
getApplicationContext().sendBroadcast(new Intent(INIENT_FINISH));
}
11.刷新adapter指定item
public void updataView(int index, Object obj, ListView listView) {
TourGuideOfCircleListBean.ContentBean contentBean = (TourGuideOfCircleListBean.ContentBean) obj;
int visibleFirstPosi = listView.getFirstVisiblePosition();
int visibleLastPosi = listView.getLastVisiblePosition();
if (index >= visibleFirstPosi && index <= visibleLastPosi) {
View view = listView.getChildAt(index - visibleFirstPosi);
ViewHolder holder = (ViewHolder) view.getTag();
holder.tv_parise_num.setText(contentBean.getPraise());
list.set(index, obj);
} else {
list.set(index, obj);
}
}
12.头布局
View headerView = getLayoutInflater().inflate(R.layout.headview_guide_business, null);