【发布时间】:2012-09-30 13:28:22
【问题描述】:
我已将 TextView 动态添加到 LinearLayout 中。 问题是,如果 TextViews 的文本比布局宽度长,它们会显示错误。 有什么方法可以使 TextViews 匹配布局宽度并从新行开始?
【问题讨论】:
我已将 TextView 动态添加到 LinearLayout 中。 问题是,如果 TextViews 的文本比布局宽度长,它们会显示错误。 有什么方法可以使 TextViews 匹配布局宽度并从新行开始?
【问题讨论】:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
使用 LinearLayout.LayoutParams
params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
txtView.setLayoutParams(params);
layout.addView(txtView);
【讨论】: