简体   繁体   中英

How to include layout at the bottom of another layout

step.xml:

<?xml version="1.0" encoding="utf-8"?>
<com.stepstone.stepper.StepperLayout 
       xmlns:android="http://schemas.android.com/apk/res/android"
       xmlns:app="http://schemas.android.com/apk/res-auto"
       android:id="@+id/stepperLayout"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       app:ms_stepperType="dots" />

activity_main.xml:

 <?xml version="1.0" encoding="utf-8"?>
    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
             xmlns:app="http://schemas.android.com/apk/res-auto"
             android:id="@+id/ScrollView01"
             android:layout_width="fill_parent"
             android:layout_height="fill_parent">

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:paddingBottom="3dp"
                  android:paddingLeft="16dp"
                  android:paddingRight="16dp"
                  android:paddingTop="3dp">

                   <android.support.design.widget.TextInputLayout
                    android:id="@+id/input_layout_name"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                    <EditText
                        android:id="@+id/firstname"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:ems="11"
                        android:maxLines="1"
                        android:hint="First name"
                        android:textColor="#000000"
                        android:maxLength="15"
                        android:tag="@+id/first_name"
                        android:textCursorDrawable="@null" />

                </android.support.design.widget.TextInputLayout>

    </RelativeLayout>

    <include
            android:id="@+id/bottom_Menu"
            android:layout_alignParentBottom="true"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            layout="@layout/step"/>

    </ScrollView>

This is the design of step.xml

在此处输入图片说明

This is the design of activity_main. In this I have included the step.xml

在此处输入图片说明

I need the output like this.

在此处输入图片说明

When I am trying to include step.xml in activity_main , I get the exception "Scroll view can only host one child view." Please help me.

Change your StepperLayout hight to wrap content .

step.xml :

<?xml version="1.0" encoding="utf-8"?>
<com.stepstone.stepper.StepperLayout 
       xmlns:android="http://schemas.android.com/apk/res/android"
       xmlns:app="http://schemas.android.com/apk/res-auto"
       android:id="@+id/stepperLayout"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       app:ms_stepperType="dots" />

And change activity_main layout as following :

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/profile_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:windowSoftInputMode="adjustResize|adjustPan">


    <LinearLayout
        android:id="@+id/profile_layout_main"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <ScrollView
            android:id="@+id/layout_scroll"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:paddingLeft="16dp"
                android:paddingRight="16dp"
                android:paddingBottom="70dp"
                android:paddingTop="3dp">

                <android.support.design.widget.TextInputLayout
                    android:id="@+id/input_layout_name"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                    <EditText
                        android:id="@+id/firstname"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:ems="11"
                        android:maxLines="1"
                        android:hint="First name"
                        android:textColor="#000000"
                        android:maxLength="15"
                        android:tag="@+id/first_name"
                        android:textCursorDrawable="@null" />

                </android.support.design.widget.TextInputLayout>

            </RelativeLayout>


        </ScrollView>


    </LinearLayout>


    <RelativeLayout
        android:id="@+id/btn_layout"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_alignParentBottom="true">

        <include
            android:id="@+id/bottom_Menu"
            android:layout_alignParentBottom="true"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            layout="@layout/step"/>

    </RelativeLayout>

</RelativeLayout>

You should make a single child inside a scrollview (just as the error says). Wrap all the children inside of another (let's say) LinearLayout or RelativeLayout with wrap_content for both the width and the height as well as the vertical orientation.

From the Docs : A ScrollView is a FrameLayout, meaning you should place one child in it containing the entire contents to scroll; this child may itself be a layout manager with a complex hierarchy of objects. A child that is often used is a LinearLayout in a vertical orientation, presenting a vertical array of top-level items that the user can scroll through.

EDIT Simplest example can be like this:

<ScrollView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1" >
      <LinearLayout android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">
           // all the views currently in your ScrollView
     </LinearLayout>
</ScrollView>

StepperLayout hight is match parent that's why it is in top position, Change you StepperLayout hight to wrap content

step.xml

    <?xml version="1.0" encoding="utf-8"?>
<com.stepstone.stepper.StepperLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/stepperLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:ms_stepperType="dots" />

And ScrollView having only one child so move your include layout inside relative layout and add android:fillViewport="true" to ScrollView

       <?xml version="1.0" encoding="utf-8"?>
    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/ScrollView01"
    android:layout_width="fill_parent"
    android:fillViewport="true"
    android:layout_height="fill_parent">

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="3dp"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:paddingTop="3dp">

 <android.support.design.widget.TextInputLayout
                    android:id="@+id/input_layout_name"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">
                    <EditText
                        android:id="@+id/firstname"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:ems="11"
                        android:maxLines="1"
                        android:hint="First name"
                        android:textColor="#000000"
                        android:maxLength="15"
                        android:tag="@+id/first_name"
                        android:textCursorDrawable="@null" />
                </android.support.design.widget.TextInputLayout>
    <include
            android:id="@+id/bottom_Menu"
            android:layout_alignParentBottom="true"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            layout="@layout/step"/>
    </RelativeLayout>

    </ScrollView>

Use this code: Once the scroll view tag has ended add the step xml code like this.

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">

<LinearLayout
        android:id="@+id/buttons"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:gravity="center"
        android:layout_alignParentBottom="true">
    <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Custom Button1"/>
    <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Custom Button2"/>
</LinearLayout>

<ScrollView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_above="@id/buttons">
     <!--Scrollable content here-->
    <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">                
        <TextView
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="test text"
                android:textSize="40dp"/>
    </LinearLayout>
</ScrollView>
 <com.stepstone.stepper.StepperLayout 
 android:id="@+id/stepperLayout"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 app:ms_stepperType="dots" />
</RelativeLayout>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM