假设textview
尺寸为18sp
,如果textview
转到第二行,如何减少textview
尺寸?
任何想法?
TextView text= (TextView)findViewById(R.id.text);
text.setTextSize(18);
//how to reduce text size if text goes to second line when it's too large?
提前致谢
答案 0 :(得分:2)
以下是您的问题的完整解决方案。 Check out this link
<强> It will automatically reduce the font size if size of your text value is greater than your view.
强>
HapPy coading .. !!
答案 1 :(得分:1)
您可以将TextWatcher绑定到textView,如下面的代码段所示,并在textView中监听文本更改。
...
txtView = (TextView)findViewById(R.id.txt);
txtView.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void afterTextChanged(Editable s) {
if(txtView.getLineCount() > 1){
txtView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
}
}
});
...
答案 2 :(得分:0)
使用spannable
String s= "Hello Everyone next line";
SpannableString ss1= new SpannableString(s);
ss1.setSpan(new RelativeSizeSpan(2f), 0,13, 0); // set size of Hello Everyone
ss1.setSpan(new RelativeSizeSpan(f), 14,23, 0);// set size of Next line
TextView tv= (TextView) findViewById(R.id.textview);
tv.setText(ss1);