【发布时间】:2018-08-27 14:51:17
【问题描述】:
当使用CollapsingToolbar 时,NestedScrollView 的滚动行为出现问题,停止工作,请帮助它看起来内容滚动仅基于 appbar_scrolling_view_behavior,但无法使用 NestedScrollView 滚动内容。一些奇怪的行为是当点击一些EditText,在片段布局和关闭虚拟键盘后,滚动工作应该是!!
库版本
// Sdk and tools
minSdkVersion = 16
targetSdkVersion = 26
compileSdkVersion = 26
buildToolsVersion = '27.0.3'
// App dependencies
supportLibraryVersion = '27.1.0'
constraintLayout = '1.1.0-beta5'
implementation "com.android.support:design:$supportLibraryVersion"
implementation "com.android.support:support-v13:$supportLibraryVersion"
implementation "com.android.support:cardview-v7:$supportLibraryVersion"
implementation "com.android.support:gridlayout-v7:$supportLibraryVersion"
implementation "com.android.support.constraint:constraint-layout:$constraintLayout"
implementation 'com.android.support:multidex:1.0.3'
UserProfileEditActivity
class UserProfileEditActivity : DaggerAppCompatActivity() {
@Inject
lateinit var appRepo: AppRepository
companion object {
fun createIntent(context: Context): Intent = Intent(context, UserProfileEditActivity::class.java)
.apply { flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP }
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_user_profile_edit)
supportFragmentManager.findFragmentById(R.id.contentContainer)
?: supportFragmentManager.beginTransaction()
.add(R.id.contentContainer, UserProfileEditFragment())
.commit()
}
}
布局:activity_user_profile_edit
只是一个重复小部件,用于测试滚动内容。
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<FrameLayout
android:id="@+id/contentContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:theme="@style/ThemeOverlay.AppCompat.Dark"
app:elevation="0dp">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/imgPeopleCover"
android:layout_width="match_parent"
android:layout_height="150dp"
android:scaleType="centerCrop"
android:src="@drawable/bg_cover_test"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
<TextView
android:id="@+id/tvToolbarTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:gravity="center_vertical"
android:text="ลิลลี่ ฮิกซ์"
android:textColor="@android:color/white"
android:textSize="20sp" />
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
布局:fragment_user_profile_edit
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/from_edge_space"
android:layout_marginStart="@dimen/from_edge_space"
android:layout_marginTop="16dp"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
style="@style/TextView.Secondary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ชื่อ" />
<EditText
style="@style/TextView.Big"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:hint="กรอกชื่อหมุด" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/from_edge_space"
android:layout_marginStart="@dimen/from_edge_space"
android:layout_marginTop="16dp"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
style="@style/TextView.Secondary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ชื่อ" />
<EditText
style="@style/TextView.Big"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:hint="กรอกชื่อหมุด" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/from_edge_space"
android:layout_marginStart="@dimen/from_edge_space"
android:layout_marginTop="16dp"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
style="@style/TextView.Secondary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ชื่อ" />
<EditText
style="@style/TextView.Big"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:hint="กรอกชื่อหมุด" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/from_edge_space"
android:layout_marginStart="@dimen/from_edge_space"
android:layout_marginTop="16dp"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
style="@style/TextView.Secondary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ชื่อ" />
<EditText
style="@style/TextView.Big"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:hint="กรอกชื่อหมุด" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/from_edge_space"
android:layout_marginStart="@dimen/from_edge_space"
android:layout_marginTop="16dp"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
style="@style/TextView.Secondary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ชื่อ" />
<EditText
style="@style/TextView.Big"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:hint="กรอกชื่อหมุด" />
</LinearLayout>
<LinearLayout
android:id="@+id/pinNameContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/from_edge_space"
android:layout_marginStart="@dimen/from_edge_space"
android:layout_marginTop="16dp"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
style="@style/TextView.Secondary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ชื่อ" />
<EditText
android:id="@+id/edtPinName"
style="@style/TextView.Big"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:hint="กรอกชื่อหมุด" />
</LinearLayout>
<LinearLayout
android:id="@+id/pinDescContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/from_edge_space"
android:layout_marginStart="@dimen/from_edge_space"
android:layout_marginTop="@dimen/from_edge_space"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/pinNameContainer">
<TextView
style="@style/TextView.Secondary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="นามสกุล" />
<EditText
android:id="@+id/edtPinDesc"
style="@style/TextView.Big"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:hint="กรอกรายละเอียด" />
</LinearLayout>
<LinearLayout
android:id="@+id/genderContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/from_edge_space"
android:layout_marginStart="@dimen/from_edge_space"
android:layout_marginTop="@dimen/from_edge_space"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/pinDescContainer">
<TextView
style="@style/TextView.Secondary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="เพศ" />
<EditText
android:id="@+id/edtGender"
style="@style/TextView.Big"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:drawableEnd="@drawable/ic_chevron_right"
android:drawableRight="@drawable/ic_chevron_right"
android:enabled="false"
android:hint="ไม่ระบุ" />
</LinearLayout>
<LinearLayout
android:id="@+id/endDateContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/from_edge_space"
android:layout_marginStart="@dimen/from_edge_space"
android:layout_marginTop="@dimen/from_edge_space"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/genderContainer">
<TextView
style="@style/TextView.Secondary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="วันสิ้นสุด" />
<TextView
android:id="@+id/tvEndDate"
style="@style/TextView.Big"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:drawableEnd="@drawable/ic_chevron_right"
android:drawableRight="@drawable/ic_chevron_right"
android:text="ไม่ระบุ" />
</LinearLayout>
<LinearLayout
android:id="@+id/privacyContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/from_edge_space"
android:layout_marginStart="@dimen/from_edge_space"
android:layout_marginTop="@dimen/from_edge_space"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/endDateContainer">
<TextView
style="@style/TextView.Secondary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ผู้เห็นหมุด " />
<TextView
android:id="@+id/tvPrivacy"
style="@style/TextView.Big"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:drawableEnd="@drawable/ic_chevron_right"
android:drawableRight="@drawable/ic_chevron_right"
android:text="สาธารณะ(คนทั่วไปเห็น)" />
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
【问题讨论】:
标签: android android-layout android-coordinatorlayout android-nestedscrollview android-collapsingtoolbarlayout