如何在我的 AppbarLayout 之后放置我的 NestedScrollView
How to place my NestedScrollView after my AppbarLayout
-
android
-
android-layout
-
android-collapsingtoolbarlayout
-
android-nestedscrollview
-
android-constraintlayout
我正在构建 colappsingToolBar,但问题是我的 NestedScrollView 显示在顶部的 AppBarLayout 中,而不是显示在 AppBarLayout 之后。我还附上了代码和图像。我在网上看过很多教程,他们也是用同样的方法做的,但我不知道为什么我的代码不起作用。
<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appabr"
android:layout_width="match_parent"
android:layout_height="250dp"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsimg_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_member_center"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="exitUntilCollapsed|scroll"
android:fitsSystemWindows="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/my_points"
android:layout_centerHorizontal="true"
android:layout_marginTop="47dp"
android:textColor="@color/white"
android:id="@+id/string"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/string"
android:layout_centerHorizontal="true"
android:text="0"
android:textColor="@color/white"
android:id="@+id/member_points"
android:textSize="26sp"
android:textStyle="bold" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/graph_member_center"
app:layout_collapseMode="parallax"
android:fitsSystemWindows="true"
android:layout_below="@+id/toolbar"
tools:ignore="NotSibling" />
<TextView
android:layout_width="wrap_content"
android:layout_height="26dp"
android:text="Silver Member"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:id="@+id/member_rank"
android:fontFamily="sans-serif-medium"
android:textColor="@color/white"
android:textSize="12sp"
android:layout_marginBottom="10dp"
/>
<ImageView
android:layout_width="23dp"
android:layout_height="26dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:src="@drawable/medal"
android:id="@+id/user_badge"
android:layout_toRightOf="@+id/member_rank"
android:layout_marginLeft="5dp"
android:layout_marginBottom="10dp"
/>
</RelativeLayout>
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
android:id="@+id/toolbar">
<ImageView
android:id="@+id/btn_back"
android:layout_width="27dp"
android:layout_height="32dp"
android:src="@drawable/ic_arrow_back"
android:tint="@color/white" />
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:id="@+id/scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="adlfjsd adsf adsf dsafasd fsda f af dsaf afl djsaflk sjdafl jsalf jsdalf jsdal fjasdl fjalsd jflas jflsa djfdl"
android:textSize="10sp"/>
</android.support.v4.widget.NestedScrollView>
</android.support.constraint.ConstraintLayout>
.
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.office.scrroabletoolbar"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:cardview-v7:28.1.0'
implementation 'com.android.support:design:28.1.0'
}
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == 'com.android.support') {
if (!requested.name.startsWith("multidex")) {
details.useVersion '26.1.0'
}
}
}
}
将容器 ConstraintLayout 更改为 CoordinatorLayout。行为只会影响协调器布局的子视图
android
android-layout
android-collapsingtoolbarlayout
android-nestedscrollview
android-constraintlayout
我正在构建 colappsingToolBar,但问题是我的 NestedScrollView 显示在顶部的 AppBarLayout 中,而不是显示在 AppBarLayout 之后。我还附上了代码和图像。我在网上看过很多教程,他们也是用同样的方法做的,但我不知道为什么我的代码不起作用。
<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appabr"
android:layout_width="match_parent"
android:layout_height="250dp"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsimg_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_member_center"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="exitUntilCollapsed|scroll"
android:fitsSystemWindows="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/my_points"
android:layout_centerHorizontal="true"
android:layout_marginTop="47dp"
android:textColor="@color/white"
android:id="@+id/string"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/string"
android:layout_centerHorizontal="true"
android:text="0"
android:textColor="@color/white"
android:id="@+id/member_points"
android:textSize="26sp"
android:textStyle="bold" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/graph_member_center"
app:layout_collapseMode="parallax"
android:fitsSystemWindows="true"
android:layout_below="@+id/toolbar"
tools:ignore="NotSibling" />
<TextView
android:layout_width="wrap_content"
android:layout_height="26dp"
android:text="Silver Member"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:id="@+id/member_rank"
android:fontFamily="sans-serif-medium"
android:textColor="@color/white"
android:textSize="12sp"
android:layout_marginBottom="10dp"
/>
<ImageView
android:layout_width="23dp"
android:layout_height="26dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:src="@drawable/medal"
android:id="@+id/user_badge"
android:layout_toRightOf="@+id/member_rank"
android:layout_marginLeft="5dp"
android:layout_marginBottom="10dp"
/>
</RelativeLayout>
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
android:id="@+id/toolbar">
<ImageView
android:id="@+id/btn_back"
android:layout_width="27dp"
android:layout_height="32dp"
android:src="@drawable/ic_arrow_back"
android:tint="@color/white" />
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:id="@+id/scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="adlfjsd adsf adsf dsafasd fsda f af dsaf afl djsaflk sjdafl jsalf jsdalf jsdal fjasdl fjalsd jflas jflsa djfdl"
android:textSize="10sp"/>
</android.support.v4.widget.NestedScrollView>
</android.support.constraint.ConstraintLayout>
.
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.office.scrroabletoolbar"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:cardview-v7:28.1.0'
implementation 'com.android.support:design:28.1.0'
}
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == 'com.android.support') {
if (!requested.name.startsWith("multidex")) {
details.useVersion '26.1.0'
}
}
}
}
将容器 ConstraintLayout 更改为 CoordinatorLayout。行为只会影响协调器布局的子视图