我有一个ScrollView和一个包含一些视图的ConstraintLayout,但是它不能滚动。我在其他相关问题中看到了一些建议,可以添加:
android:fillViewport="true"
我曾尝试使用NestedScrollView并更改ScrollView的位置,但没有帮助。
我的碎片布局如下:
<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:fillViewport="true"
>
<android.support.constraint.ConstraintLayout
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:id="@+id/layout_style"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:paddingEnd="?attr/listPreferredItemPaddingRight"
android:paddingStart="?attr/listPreferredItemPaddingLeft"
android:paddingTop="?attr/listPreferredItemPaddingLeft"
>
<TextView
android:id="@+id/lbl_style"
style="@style/HeadSection"
android:text="@string/label_style"
app:layout_constraintStart_toStartOf="@+id/guideline_label_margins"
app:layout_constraintTop_toBottomOf="@+id/txt_beer_description"/>
<TextView
android:id="@+id/lbl_short_style"
style="@style/Label"
android:text="@string/label_short_style"
app:layout_constraintStart_toStartOf="@+id/guideline_label_margins"
app:layout_constraintTop_toBottomOf="@+id/lbl_style_name"/>
<TextView
android:id="@+id/txt_short_style"
style="@style/Content"
app:layout_constraintStart_toStartOf="@+id/guideline_content_margins"
app:layout_constraintTop_toBottomOf="@+id/txt_style_name"
tools:text="American Dark Lager"/>
<TextView
android:id="@+id/lbl_style_name"
style="@style/Label"
android:text="@string/label_style_name"
app:layout_constraintStart_toStartOf="@+id/guideline_label_margins"
app:layout_constraintTop_toBottomOf="@+id/lbl_style"/>
<TextView
android:id="@+id/txt_style_name"
style="@style/Content"
app:layout_constraintStart_toStartOf="@+id/guideline_content_margins"
app:layout_constraintTop_toBottomOf="@+id/lbl_style"
tools:text="American-Style Dark Lager"/>
<TextView
android:id="@+id/lbl_style_category_name"
style="@style/Label"
android:layout_height="19dp"
android:text="@string/label_style_category_name"
app:layout_constraintStart_toStartOf="@+id/guideline_label_margins"
app:layout_constraintTop_toBottomOf="@+id/lbl_short_style"/>
<TextView
android:id="@+id/txt_style_category_name"
style="@style/Content"
app:layout_constraintStart_toStartOf="@+id/guideline_content_margins"
app:layout_constraintTop_toBottomOf="@+id/txt_short_style"
tools:text="North American Lager"/>
<TextView
android:id="@+id/lbl_beer"
style="@style/HeadSection"
android:layout_marginLeft="16dp"
android:layout_marginTop="4dp"
android:text="@string/label_detail_head_beer_info"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<TextView
android:id="@+id/lbl_beer_name"
style="@style/Label"
android:text="@string/label_detail_beer_name"
app:layout_constraintStart_toStartOf="@+id/guideline_label_margins"
app:layout_constraintTop_toBottomOf="@+id/lbl_beer"/>
<TextView
android:id="@+id/txt_beer_name"
style="@style/Content"
app:layout_constraintStart_toStartOf="@+id/guideline_content_margins"
app:layout_constraintTop_toBottomOf="@+id/lbl_beer"
tools:text="Heineken"/>
<TextView
android:id="@+id/lbl_beer_Description"
style="@style/Label"
android:text="@string/label_detail_beer_description"
app:layout_constraintStart_toStartOf="@+id/guideline_label_margins"
app:layout_constraintTop_toBottomOf="@+id/lbl_beer_name"/>
<TextView
android:id="@+id/txt_beer_description"
style="@style/Content"
android:layout_width="0dp"
android:layout_marginEnd="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/guideline_content_margins"
app:layout_constraintTop_toBottomOf="@+id/lbl_beer_Description"/>
<android.support.constraint.Guideline
android:id="@+id/guideline_label_margins"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_begin="16dp"/>
<android.support.constraint.Guideline
android:id="@+id/guideline_content_margins"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_begin="120dp"/>
</android.support.constraint.ConstraintLayout>
</ScrollView>
这个布局是在一个片段中填充的,该片段是:
content_detail.xml:
<fragment
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/fragment_detail"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
/>
还有根布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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:id="@+id/layout_detail"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="@dimen/card_height_huge"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
>
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"
/>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<include
layout="@layout/content_detail"/>
</android.support.design.widget.CoordinatorLayout>
这个行为存在一个关于此bug的报告。
我发现了一个本应被修复的bug,但其他一些相关用户仍然报告了该问题:
https://issuetracker.google.com/issues/37115702
-- EDIT
当我旋转手机时,txt_beer_description
TextView会超出屏幕。所以如果我滚动,滚动条只能滚到txt_beer_description的末尾,无法继续滚动。
-- EDIT
样式文件如下:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@android:color/black</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="SearchBeerItemBaseText">
<item name="android:gravity">start|center_vertical</item>
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_marginStart">8dp</item>
</style>
<style name="SearchBeerItemTextPrimary" parent="SearchBeerItemBaseText">
<item name="android:textColor">@color/primary_text</item>
<item name="android:textSize">16sp</item>
</style>
<style name="SearchBeerItemTextSecundary" parent="SearchBeerItemBaseText">
<item name="android:textColor">@color/secondary_text</item>
<item name="android:textSize">14sp</item>
</style>
<style name="CollectionItemBaseText">
<item name="android:gravity">start|center_vertical</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
</style>
<style name="CollectionItemTextPrimary" parent="CollectionItemBaseText">
<item name="android:textColor">@color/white</item>
<item name="android:textSize">15sp</item>
<item name="android:focusable">false</item>
<item name="android:focusableInTouchMode">false</item>
<item name="android:clickable">false</item>
</style>
<style name="CollectionItemTextSecundary" parent="CollectionItemBaseText">
<item name="android:textColor">@color/white</item>
<item name="android:textSize">13sp</item>
</style>
<style name="SearchActivityPrimaryImage">
<item name="android:layout_width">56dp</item>
<item name="android:layout_height">56dp</item>
</style>
<style name="HeadSection">
<item name="android:layout_marginTop">16dp</item>
<item name="android:layout_marginBottom">8dp</item>
<item name="android:textStyle">bold</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textColor">@color/primary</item>
<item name="android:textAppearance">@style/TextAppearance.AppCompat.Subhead</item>
</style>
<style name="Label">
<item name="android:textStyle">bold</item>
<item name="android:layout_marginTop">16dp</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textColor">@color/primary_text</item>
<item name="android:textAppearance">@style/TextAppearance.AppCompat.Body1</item>
</style>
<style name="Content" >
<item name="android:layout_marginTop">16dp</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textColor">@color/secondary_text</item>
<item name="android:textAppearance">@style/TextAppearance.AppCompat.Body1</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"/>
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"/>
</resources>