1.scrollview中嵌套有listview或者gridview,从其他页面返回到这个页面,焦点总是跑到listview或者gridview上
解决办法:重写scrollview的下边方法
@Override
protected int computeScrollDeltaToGetChildRectOnScreen(Rect rect) {
return 0;
}
2.webview清除缓存的方法:
webview.clearCache(true);
webview.clearHistory();
3.图片和文字的组合显示可以使用下边方法:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="12dp"
android:drawableLeft="@drawable/meal"
android:drawablePadding="15dp"
android:gravity="center_vertical"
android:text="推荐"
android:textColor="@color/default_left_content_color" />
4.图片底部写文字,可以用下边的办法:
/**
* 带文字的图片
*/
public class TextImageView extends ImageView {
protected Context mContext;
private float textSize; // 文字大小
private String text;
private Paint paint;
private TextPaint textPaint;
private TextImageView textImageView;
public TextImageView(Context context) {
super(context);
this.textImageView = this;
init(context);
}
public TextImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
this.textImageView = this;
init(context);
}
public TextImageView(Context context, AttributeSet attrs) {
super(context, attrs);
this.textImageView = this;
init(context);
}
/**
* @param context
*/
private void init(Context context) {
this.mContext = context;
paint = new Paint();
paint.setColor(Color.parseColor("#7f000000")); // 颜色
paint.setStyle(Paint.Style.FILL);
paint.setStrokeWidth(5);
textPaint = new TextPaint();// 初始化画笔,为后面文字使用。
textPaint.setAntiAlias(true);// 去除锯齿。
try {
textPaint.setTextSize(mContext.getResources().getDimension(
R.dimen.size_28px)); // 设置文字大小
} catch (Exception e) {
}
textPaint.setColor(Color.WHITE); // 颜色
textPaint.setTextAlign(Paint.Align.CENTER);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
// 画边框
Rect rec = canvas.getClipBounds();
int top = rec.bottom;
int left = rec.left;
int right = rec.right;
int bottom = rec.bottom;
RectF rectf = new RectF(left, 0.8f * top, right, bottom);
canvas.drawRect(rectf, paint);
int textWidth = 0;
try {
textWidth = (int) textPaint.measureText(text);// 获取字体的宽度
} catch (Exception e) {
}
String ellipsizeStr = "";
int boottomtextWidth = getMeasuredWidth() - 15;
if (textWidth > boottomtextWidth) {
ellipsizeStr = (String) TextUtils.ellipsize(text, textPaint,
boottomtextWidth, TextUtils.TruncateAt.END);
} else {
ellipsizeStr = text;
}
if (StringTools.isNotEmpty(ellipsizeStr)) {
canvas.drawText(ellipsizeStr, 0.5f * right, 0.95f * top, textPaint);
}
}
public float getTextSize() {
return textSize;
}
public void setTextSize(float textSize) {
this.textSize = textSize;
}
public String getText() {
return text;
}
public void setTitle(String text) {
this.text = text;
}
public void setImage(String picUrl) {
AsynImageLoader.getInsatnce(mContext).showImageAsyn(this.textImageView,Format.null2Blank(picUrl));
}
}
5.Activity中viewpager嵌套多个子activity,子activity生命周期的调用
protected LocalActivityManager manager = null;
...
manager = new LocalActivityManager(this, true);
...
@Override
public void onResume() {
super.onResume();
dealPreviousActivity(lastIndex + 1, false);
}
@Override
protected void onStop() {
dealPreviousActivity(1, true);
super.onStop();
}
private void dealPreviousActivity(int index, boolean isOnStop) {
if (manager != null) {
Activity _activity = manager.getActivity("" + index);
if (_activity == null)
return;
if (_activity instanceof HomeActivity) {
if (isOnStop)
((HomeActivity) _activity).goneOnScreen();
else
((HomeActivity) _activity).invisibleOnScreen();
}
}
}