Second layout not showing with include tag in android studio

I designed two Android layouts that should be shown in order. So, the first layout should be displayed at the top of the page, and the second layout should be displayed at the bottom of the page. However, the following code shows only the first layout. How can I show the second layout too?

main layout

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

The first xml layout 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: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" />
</LinearLayout>

Second layout

<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>
+6
source share
4 answers

I'm still not sure that this will solve your problem, but can you try adding android:layout_widthboth the android:layout_heightweight of the layout to your included layout?

<include layout="@layout/first_layout"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"/>

<include layout="@layout/second_layout"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"/>

Information added

, , , match_parent. , ( ), , , .

, layout_weight.

+5

android:layout_height="match_parent"

.

android:layout_height="wrap_content"

.

, , , .

,

( android:layout_*) , <include/>.

+3

RelativeLayout . LinearLayout, , match_parent, .

+1

, Android " ". xml TextView, . xml TextView, , , . ? , , Stackoverflow. , Android , . 20 .

0

Source: https://habr.com/ru/post/1629833/


All Articles