2016-02-19 92 views
0

我在android studio中有兩個單獨的xml文件。 我想在單一佈局中顯示它們。任何人都可以指導我分別給他們看。此外,在設計選項卡,我不能添加一些按鈕或其他組件爲什麼?在android studio中合併兩個基於XML的android佈局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" 
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
android:paddingBottom="@dimen/activity_vertical_margin" 
tools:context="net.simplifiedcoding.androidloginapp.UserProfile"> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:text="Large Text" 
    android:id="@+id/textView3" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" /> 
</RelativeLayout> 

第二個是

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" 
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:orientation="vertical" 
android:paddingTop="@dimen/activity_vertical_margin" 
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Name" 
    android:id="@+id/textView" /> 

<EditText 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/editTextName" /> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Address" 
    android:id="@+id/textView2" /> 

<EditText 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/editTextAddress" /> 

<Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Insert" 
    android:onClick="insert" 
    android:id="@+id/button" /> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/textViewResult" /> 
</LinearLayout> 
+0

看看這個解決方案,並採取決定你想達到什麼http://stackoverflow.com/a/20874215/1206052 – DeltaCap

回答

0

你可以使用包括標籤。 Chech here爲一個完整的例子。 綜上所述,您將創建第三個佈局,看起來像財產以後這樣的:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <include layout="@layout/first_layout"/> 
    <include layout="@layout/second_layout"/> 

</LinearLayout> 
+0

感謝您的回覆。你的意思是我應該製作兩個單獨的XML文件作爲first_layout.xml和second_layout.xml,然後編寫上面的代碼? –

+0

@amirghasemi是的,你需要創建單獨的佈局,然後將它們合併到一個在上面的答案中提到的方式 – DeltaCap

+0

親愛的朋友我做了兩個名爲first_layout.xml和second_layout.xml和上述XML文件的XML文件。但是,它只是顯示我first_layout.xml :(這是什麼問題? –