在我的应用程序中,我需要将动态文本设置为我的textview,所以我希望它动态调整大小.我已经设定:
<TextView
android:id="@+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="normal"
android:text="Frontview"
android:layout_weight="1"
android:gravity="center_vertical"
android:textColor="#0099CC"
android:singleLine="false"
android:maxLines="4"
android:ellipsize="marquee"
/>
Run Code Online (Sandbox Code Playgroud)
我的textview高度不超过2行,文字正在削减.有人可以帮忙吗?
Thanx提前.
Aar*_*n C 17
正如康斯坦丁所说,除非你删除,否则你的超过4行后可能会忽略此代码 android:maxLines="4"
这是你在代码中设置高度的方法:
TextView tv = (TextView) findViewById(R.id.TextView02);
int height_in_pixels = tv.getLineCount() * tv.getLineHeight(); //approx height text
tv.setHeight(height_in_pixels);
Run Code Online (Sandbox Code Playgroud)
如果您想使用dip单位(允许您的应用在多个屏幕尺寸上缩放),您可以将像素数乘以返回的值. getResources().getDisplayMetrics().density;
这取决于您所需的行为,但您也可以考虑修复TextView大小,并允许用户滚动文本:
TextView tv = (TextView)findViewById(R.id.TextView02);
tv.setMovementMethod(ScrollingMovementMethod.getInstance());
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
52629 次 |
| 最近记录: |