Java 如何在另一个布局的底部包含布局
step.xml:Java 如何在另一个布局的底部包含布局,java,android,Java,Android,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/stepp
<?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>
这是活动的设计。在本文中,我包含了step.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>
当我试图在活动_main
中包含step.xml
时,出现异常“Scroll view只能承载一个子视图”。请帮助我。您应该在Scroll view
中创建一个子视图(正如错误所述)。用Wrap_content
将另一个(比方说)LinearLayout
或RelativeLayout
的宽度和高度以及垂直方向将所有子对象包裹在另一个(比如)的内部
从:
ScrollView是一个框架布局,这意味着您应该在其中放置一个子元素,其中包含要滚动的全部内容;此子对象本身可能是具有复杂对象层次结构的布局管理器。通常使用的子项是垂直方向的线性布局,表示用户可以滚动的顶级项的垂直数组
编辑
最简单的例子如下:
<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>
//当前在ScrollView中的所有视图
StepperLayout hight是匹配的父项,这就是为什么它处于顶部位置,请将您的StepperLayouthight更改为包装内容
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" />
ScrollView只有一个子视图,因此移动将布局包含在相对布局中并将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>
使用此代码:滚动视图标记结束后,添加如下步骤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>
将StepperLayout High更改为包装内容
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" />
<?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>
并将活动单元主布局更改如下:
活动\u main.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" />
<?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>
您不能这样做。阅读有关xml编码的基本文档。最重要的标记只有一个子标记。那么如何将step.xml添加到活动_main?有什么解决办法吗@RakeshPolo@J RameshAdd包含相对线内布局tag@sagar在StepperLayout中,使用wrap_内容而不是match_parentI将StepperLayout hight更改为wrap内容,即使内容包含在顶部但不包含在底部。检查代码后。@Mohit SutharAlso,将步骤布局添加到相对布局中是的,我使用了相同的代码,但添加到了顶部。android:fillViewport=“true”将此添加到ScrollView中您的问题将得到解决,先生,您在代码中包含了步骤布局吗?这只是一个示例。如果要在滚动视图中添加更多内容,则应将步进器布局和其他ui元素放入子布局(在本例中为LinearLayout)中,然后将滚动视图的子布局设置为线性布局(垂直),而不是相对布局。如果此答案解决了您的问题,请将其标记为正确。