2011-07-21 8 views

答えて

1
 <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> 

そして、必要なパラメータと必要なパラメータを配置するだけで、このレイアウトを拡張できます。

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); 
+0

ビューv = inflater.inflate(R.layout.whereyouwant、null); どういう意味ですか(どこですか) –

+0

おっと、申し訳ありませんが、表示したいレイアウトを展開しました。 mynewlayout.xmlのようなXMLコードに名前を付けます。 R.layout.mynewlayout –

0

こんにちは、RelativeViewでは縦方向と呼ばれるものは何もありません。 RelativeLayout内のウィジェットは、互いに相対的な位置に配置されます。だから、あなたが別のものの下に来るように1つの線形レイアウトを作成した場合、元のレイアウトのためにあなたはandroid:layout_below属性を必要とします。

+0

多分、彼は直線レイアウトのための垂直方向を意味しました。それとも私は彼をそのようにした。 LOL :) –

+0

私は直線レイアウトのための垂直方向を意味します。 –

関連する問題