Using ViewTreeObserver i am adding setMaxLines and setEllipsize in MaterialTextView inside RecyclerView.Adapter

后端 未结 3 1991
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-12 06:28
  • I am set MaterialTextView inside RelativeLayout and set RelativeLayout size programmatically different size for every device.

3条回答
  •  南方客
    南方客 (楼主)
    2020-12-12 07:01

    I have using this. works perfectly

    textView.setText(subCategoryLists.get(position).getStatus_title());
    textView.post(new Runnable() {
        @Override
        public void run() {
            ViewGroup.LayoutParams params = textView.getLayoutParams();
            if (params == null) {
                params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
            }
            final int widthSpec = View.MeasureSpec.makeMeasureSpec(textView.getWidth(), View.MeasureSpec.UNSPECIFIED);
            final int heightSpec = View.MeasureSpec.makeMeasureSpec(textView.getHeight(), View.MeasureSpec.UNSPECIFIED);
            textView.measure(widthSpec, heightSpec);
            textView.setMaxLines(heightSpec / textView.getLineHeight());
            textView.setEllipsize(TextUtils.TruncateAt.END);
        }
    });
    

提交回复
热议问题