[英]How to include layout at the bottom of another layout
step.xml: 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: 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 这是step.xml的设计
This is the design of activity_main. 这是activity_main的设计。 In this I have included the step.xml
在此,我包括了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." 当我尝试在
activity_main
包含step.xml
时,出现异常“滚动视图只能承载一个子视图”。 Please help me. 请帮我。
Change your StepperLayout hight to wrap content . 更改您的StepperLayout高度以包装内容 。
step.xml : 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布局:
activity_main.xml: 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). 您应该在
scrollview
内生一个scrollview
(正如错误所述)。 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. 将所有子项都包装在另一个(例如)
LinearLayout
或RelativeLayout
并用wrap_content
来获取宽度和高度以及垂直方向。
From the Docs : A ScrollView is a FrameLayout, meaning you should place one child in it containing the entire contents to scroll; 在Docs中 :ScrollView是一个FrameLayout,这意味着您应在其中放置一个包含要滚动的全部内容的子元素。 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.
经常使用的子项是在垂直方向上的LinearLayout,它显示用户可以滚动浏览的顶级项目的垂直数组。
EDIT Simplest example can be like this: EDIT最简单的示例可以像这样:
<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 StepperLayout高是匹配的父级,这就是为什么它处于最高位置,请更改您的StepperLayout高以包装内容
step.xml 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 并且ScrollView只有一个孩子,因此将您的include布局移动到相对布局内 ,并将android:fillViewport =“ true”添加到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代码,如下所示。
<?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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.