Why setting text from onMeasure does not affect TextView?

前端 未结 7 1134
走了就别回头了
走了就别回头了 2021-01-13 12:36

There is a TextView of a certain size and whenever text set to it is too long I\'d like to re-set it to some preset value.

To accomplish this I am overr

7条回答
  •  礼貌的吻别
    2021-01-13 12:48

    You will want to implement Textwatcher and in the onTextChanged(...) method, call TextView's setEms(...) method, which will set the width of the TextView to the width of (n m's), where n is the input for setEms(...).

    ...
    TextView tv = (TextView) findViewById(R.id.my_text_view);
    tv.addTextChangedListener(this);
    ...
    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
        tv.setEms(count);
    }
    

提交回复
热议问题