How do I change the height of an item in a ListView?

I am using auto-resizing TextView as an item in my ListView. This widget overrides onMeasure () and sets the height to half the width. Thus, the text complies with these restrictions. This widget also has a listener called when the font size changes. If, for example, the new font size is less than 14 dp, I need to set the height of the widget to its width. So I set a new value for the checkbox 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 the requestLayout () does not result. So how can I change the height of the ListViews and start measuring it?

+3


source to share





All Articles