在我的活动布局文件中,我定义了一个AppBarLayout
,其中包含Toolbar
。然后我从另一个文件中包含Activity
的主要内容,该文件应该是可滚动的。在工具栏下包含可滚动布局
我可以滚动第二个活动的内容,但是当滚动到底部时,布局的某些部分刚刚被剪掉。 (我看不到底部的按钮)。我不希望Toolbar
是可滚动的,只有内容。
activity_first:
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#FFF"
tools:context=".StartScreens.Home.HomeScreens.FirstActivity"
xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.design.widget.AppBarLayout
android:id="@+id/Activity_AppBar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<include android:id="@+id/Activity_Toolbar"
layout="@layout/toolbar" />
</android.support.design.widget.AppBarLayout>
<include android:id="@+id/Activity_First_Content_Include"
layout="@layout/activity_first_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/Activity_AppBar"/>
</android.support.constraint.ConstraintLayout>
activity_first_content
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFF"
tools:context=".StartScreens.Home.HomeScreens.FirstActivity">
<!-- Content -->
<EditText
android:id="@+id/EditText_Title"
android:layout_width="wrap_content"
android:layout_height="42dp"
android:layout_marginStart="20dp"
android:layout_marginTop="10dp"
app:layout_constraintTop_toBottomOf="parent"
android:ems="10" />
<RatingBar
android:id="@+id/Activity_RatingBar_Stars"
android:layout_width="241dp"
android:layout_height="42dp"
app:layout_constraintLeft_toRightOf="@+id/TextView_Stars"
android:inputType="number"
android:maxLength="1"
app:layout_constraintTop_toBottomOf="@+id/EditText_Title"
android:layout_marginStart="20dp" />
<!-- A lot more content -->
<Button
android:id="@+id/Button_Clear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="Clear"
android:text="@string/clear"
android:layout_marginTop="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintVertical_bias="0.775"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/Button_Submit" />
<Button
android:id="@+id/Button_Submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="ButtonClickSubmit"
android:text="@string/submit"
android:layout_marginTop="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintVertical_bias="0.775"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toRightOf="@+id/Button_Clear" />
</android.support.constraint.ConstraintLayout>
</ScrollView>
如果我app:layout_constraintTop_toBottomOf="parent">
加入这一行的AppBarLayout
,我可以滚动查看所有内容,甚至按钮。但是包含的内容显示在AppBar
/Toolbar
之上,并且Toolbar
已消失。总之,我的布局是可滚动的,但最下面的两个按钮被切掉。当滚动到底部时,屏幕右边缘的灰色滚动条会一直保持“在屏幕下”/“过去”的位置。
任何想法,我可以如何提高我的代码?
只是一个简单的问题,在你activity_first_content布局,在那里,你已经在你的RatingBar – Nero
这个布局文件是巨大提到你TextView_Stars元素,所以我只是切出很多内容。我知道现在的代码可能没有什么意义,但是文件的内容并不重要。布局工作正常,只是不滚动 – Fred
在您的顶级XML文件中,您的''标签使用'wrap_content'高度。如果将其更改为'0dp'并添加'app:layout_constraintBottom_toBottomOf =“parent”',它会起作用吗? –