我在线性布局中动态添加视图,如下所示:
xml:
<LinearLayout
android:id="@+id/part1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:gravity="right"
android:orientation="horizontal" >
</LinearLayout>
爪哇:
View linearLayout = findViewById(R.id.part1);
((LinearLayout) linearLayout).removeAllViews();
for (int i = 0; i < 15; i ++){
TextView tv = new TextView(this);
tv.setText(String.valueOf(i));
LinearLayout.LayoutParams lay = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
tv.setLayoutParams(lay);
tv.setBackgroundResource(R.drawable.msg);
tv.setId(i);
((LinearLayout) linearLayout).addView(tv);
}
现在我有两个问题:
1)文本视图被正确水平添加,但如果不适合屏幕尺寸,其中一些不会出现,一旦水平空间已满,如何强制它继续添加新行?
2)文本视图是从左到右添加的,如何从右到左添加?
谢谢