0

I have two separate xml files in android studio. I would like to show them in single layout. can anyone guide me to show them respectively. Also, in design tab I cannot add some button or other component why?

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

The second one is

<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>
amir ghasemi
  • 13
  • 2
  • 7

1 Answers1

0

You could use the include tag. Chech here for a complete example. To sum up, you would create a third layout which would look like somthing like that:

<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>
malrok44
  • 592
  • 6
  • 17
  • Thanks for your respond. You mean I should make two separate xml files as first_layout.xml and second_layout.xml then write the above code? – amir ghasemi Feb 19 '16 at 08:57
  • @amirghasemi yes you need to create separate layouts then merge them into one the way mentioned in above answer – DeltaCap019 Feb 19 '16 at 09:45
  • Dear friend I have made two xml files with names first_layout.xml and second_layout.xml and the above xml file. However, it just shown me first_layout.xml :( what is the problem ? – amir ghasemi Feb 19 '16 at 09:54
  • This answer doesn't take into account that the second layout is pushed off-screen when the first layout has a `match_parent` height... – MH. Feb 19 '16 at 10:18
  • then what should i have to do? – amir ghasemi Feb 22 '16 at 01:48