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
android android-listview


source to share


No one has answered this question yet

Check out similar questions:

3295
Why is the Android emulator so slow? How can we speed up the development of an Android emulator?
2510
How to persist android activity state by persisting instance state?
2284
How can I fix 'android.os.NetworkOnMainThreadException'?
1844
How to place text horizontally and vertically in a TextView?
1832
Lazy loading images in ListView
402
How do I update my Android watchlist?
390
How do I change the line color of the separator line of an Android ListView?
363
Android ListView spacing
0
Android: CardView extension whose content can be extended
0
android custom view onmeasure TextView



All Articles
Loading...
X
Show
Funny
Dev
Pics