如何在Java中并排显示两个文本视图?
我成功地用XML做了!
我的代码:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12dip"
android:layout_marginRight="10dp"
android:layout_alignParentLeft="true"
android:textColor="#ffffff" />
<TextView
android:id="@+id/value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12dip"
android:layout_alignParentRight="true"
android:textColor="#ffffff" />
</RelativeLayout>
最佳答案
在我的LinearLayout
中创建一个activity_layout
。
LinearLayout lm=(LinearLayout) findViewById(R.id.Linearlayout1);
动态地使
LinearLayout
类型水平。 LinearLayout llh=new LinearLayout(context);
llm.setOrientation(LinearLayout.HORIZONTAL);
然后动态创建两个
TextView tv1=new TextView(context);
TextView tv2=new TextView(context);
最后将这两个
TextView
添加到水平TextView
(我们动态创建的)中,然后将同一布局添加到xml布局中。llh.addView(tv1);
llh.addView(tv2);
lm.addView(llh);
我希望这会有帮助。