How to set two linearlayout in relativelayout dynamically with vertical 开发者_运维问答orientation .And how to add controls in two linearlayout.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:id="@+id/yourlayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout android:id="@+id/linearLayout1"
android:orientation="vertical"
android:layout_alignParentLeft="true"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 1"
></Button>
</LinearLayout>
<LinearLayout android:id="@+id/linearLayout2"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_alignParentRight="true"
android:layout_height="fill_parent" >
<Button android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 2"
></Button>
</LinearLayout>
</RelativeLayout>
And you can just inflate this layout where you want and parameters you want.
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflater.inflate(R.layout.whereyouwant, null);
RelativeLayout rl = (RelativeLayout)findViewById(R.id.yourlayout);
RelativeLayout.LayoutParams parametri = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
parametri.addRule(RelativeLayout.ALIGN_PARENT_TOP);
rl.addView(v, parametri);
v.setVisibility(View.VISIBLE);
hi There's nothing called vertical orientation for RelativeView. Widget inside RelativeLayout are place in relative postions to eachother. So if you wnat one linearlayout to come below of another .. you need to user android:layout_below attribute for former layout.
精彩评论