I use auto resizing TextView as item in my ListView. This widget overrides onMeasure() and set height equal half of width. So text fits in this bounds. This widget also has listener, that called, when font size is changed. If new font size less than 14dp for example, I need to set height of widget equal to its width. So i set new value to flag and call requestLayout().
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int width = getMeasuredWidth();
int height = width;
if (halfSize) {
height = width / 2;
}
setMeasuredDimension(width, height);
}
private void init(Context context) {
this.context = context;
final float halfModeMinFontSize = DisplayUtils.dpToPx(context, 14);
setOnResizeListener(new OnTextResizeListener() {
@Override
public void onTextResize(TextView textView, float oldSize, float newSize) {
if (newSize < halfModeMinFontSize) {
setHalfSize(false);
}
}
});
}
But calling of requestLayout() doesn't result. So how can I change height of ListViews item and initiate its measure?
0 comments:
Post a Comment