2017-11-25 74 views
0

在我的活动布局文件中,我定义了一个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已消失。总之,我的布局是可滚动的,但最下面的两个按钮被切掉。当滚动到底部时,屏幕右边缘的灰色滚动条会一直保持“在屏幕下”/“过去”的位置。

任何想法,我可以如何提高我的代码?

+0

只是一个简单的问题,在你activity_first_content布局,在那里,你已经在你的RatingBar – Nero

+0

这个布局文件是巨大提到你TextView_Stars元素,所以我只是切出很多内容。我知道现在的代码可能没有什么意义,但是文件的内容并不重要。布局工作正常,只是不滚动 – Fred

+0

在您的顶级XML文件中,您的''标签使用'wrap_content'高度。如果将其更改为'0dp'并添加'app:layout_constraintBottom_toBottomOf =“parent”',它会起作用吗? –

回答

0

我花了一些时间来处理您发布的布局,如果您为包含添加底部约束,我可以重现您的原始问题以及完全消失布局的问题。

我无法解决问题,同时将ConstraintLayout保留为顶层视图,但如果将其切换为LinearLayout,则问题很容易解决。然后你就可以有这样的布局:

<LinearLayout 
    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="wrap_content" 
    android:background="#FFF" 
    android:orientation="vertical" 
    tools:context=".StartScreens.Home.HomeScreens.FirstActivity"> 

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

     <include 
      layout="@layout/toolbar" 
      android:id="@+id/Activity_Toolbar"/> 

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

    <include 
     layout="@layout/activity_first_content" 
     android:id="@+id/Activity_First_Content_Include" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"/> 

</LinearLayout> 
相关问题