我要制作CollapsibleToolbar。查看嵌入的gif。 https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&fname=https%3A%2F%2Fk.kakaocdn.net%2Fdn%2Fb1H8Rj%2FbtqwrADyPUy%2FUV2LzlICIaQXhIPqIazATK%2Fimg.gif
在end_scene,工具栏具有填充,尽管其填充为空。 他们发生了什么?
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("Testing")),
body: Center(
child: RaisedButton(
child: Text("Show dialog"),
onPressed: () {
showDialog(
context: context,
builder: (context) {
return Dialog(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(40)),
elevation: 16,
child: Container(
height: 400.0,
width: 360.0,
child: ListView(
children: <Widget>[
SizedBox(height: 20),
Center(
child: Text(
"Leaderboard",
style: TextStyle(fontSize: 24, color: Colors.blue, fontWeight: FontWeight.bold),
),
),
SizedBox(height: 20),
_buildName(imageAsset: 'assets/chocolate.jpg', name: "Name 1", score: 1000),
_buildName(imageAsset: 'assets/chocolate.jpg', name: "Name 2", score: 2000),
_buildName(imageAsset: 'assets/chocolate.jpg', name: "Name 3", score: 3000),
_buildName(imageAsset: 'assets/chocolate.jpg', name: "Name 4", score: 4000),
_buildName(imageAsset: 'assets/chocolate.jpg', name: "Name 5", score: 5000),
_buildName(imageAsset: 'assets/chocolate.jpg', name: "Name 6", score: 6000),
],
),
),
);
},
);
},
),
),
);
}
Widget _buildName({String imageAsset, String name, double score}) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 20.0),
child: Column(
children: <Widget>[
SizedBox(height: 12),
Container(height: 2, color: Colors.redAccent),
SizedBox(height: 12),
Row(
children: <Widget>[
CircleAvatar(
backgroundImage: AssetImage(imageAsset),
radius: 30,
),
SizedBox(width: 12),
Text(name),
Spacer(),
Container(
padding: EdgeInsets.symmetric(vertical: 8, horizontal: 20),
child: Text("${score}"),
decoration: BoxDecoration(
color: Colors.yellow[900],
borderRadius: BorderRadius.circular(20),
),
),
],
),
],
),
);
}
Part of content_main.xml
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
android:theme="@style/AppTheme.AppBarOverlay">
<foo.bar.CollapsibleToolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/constraintToolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:layoutDescription="@xml/main_motion"
android:minHeight="160dp"
app:layout_scrollFlags="scroll|enterAlways|snap|exitUntilCollapsed">
<TextView
android:id="@+id/month"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="40sp"
android:textColor="#000000"
android:text="April"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<TextView
android:id="@+id/month_goal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/month"
android:textSize="18sp"
android:text="1/30"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/month"/>
<ImageView
android:id="@+id/app_icon"
android:layout_width="60dp"
android:layout_height="60dp"
android:src="@drawable/ic_launcher"
android:contentDescription="@string/this_app_name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<com.dinuscxj.progressbar.CircleProgressBar
android:id="@+id/days_graph"
android:layout_width="128dp"
android:layout_height="128dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toTopOf="@+id/name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.24000001"
app:layout_constraintVertical_chainStyle="packed"
app:line_width="20dp"
app:progress_end_color="@color/colorAccent"
app:progress_shader="sweep"
app:progress_start_color="@color/colorPrimary"
app:progress_start_degree="-90"
app:progress_stroke_cap="round"
app:progress_stroke_width="20dp"
app:progress_text_color="@android:color/black"
app:style="solid_line" />
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/cv_profile"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:background="@color/colorWhite"
android:elevation="@dimen/cardview_elevation"
android:clickable="true"
android:focusable="true"
android:foreground="@drawable/selector_ripple"
android:contentDescription="Profile"
android:src="@drawable/img_default_profile"
app:layout_constraintStart_toStartOf="@+id/days_graph"
app:layout_constraintEnd_toEndOf="@+id/days_graph"
app:layout_constraintTop_toTopOf="@+id/days_graph"
app:layout_constraintBottom_toBottomOf="@id/days_graph"/>
<ImageView
android:id="@+id/circle_profile_overlay"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:alpha="1"
android:contentDescription="Profile"
android:scaleType="fitCenter"
android:src="@drawable/ic_check_circle"
android:elevation="2dp"
app:layout_constraintStart_toStartOf="@+id/days_graph"
app:layout_constraintEnd_toEndOf="@+id/days_graph"
app:layout_constraintTop_toTopOf="@+id/days_graph"
app:layout_constraintBottom_toBottomOf="@+id/days_graph" />
<TextView
android:id="@+id/graph_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:bufferType="spannable"
android:text="30/365"
android:textColor="@android:color/black"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/days_graph" />
<TextView
android:id="@+id/change_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textColor="@android:color/black"
android:layout_marginStart="@dimen/usual_margin"
android:layout_marginEnd="@dimen/usual_margin"
android:bufferType="spannable"
android:text="@string/click_to_change_goal"
android:textAlignment="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/name"/>
</foo.bar.CollapsibleToolbar>
</com.google.android.material.appbar.AppBarLayout>
main_moton_end.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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:orientation="vertical">
<TextView
android:id="@+id/month"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="40sp"
android:textColor="#000000"
android:text="April"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<TextView
android:id="@+id/month_goal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/month"
android:textSize="18sp"
android:text="1/30"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/month"/>
<ImageView
android:id="@+id/app_icon"
android:layout_width="60dp"
android:layout_height="60dp"
android:src="@drawable/ic_launcher"
android:contentDescription="@string/this_app_name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<com.dinuscxj.progressbar.CircleProgressBar
android:id="@+id/days_graph"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
app:line_width="5dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/cv_profile"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_gravity="center"
android:src="@drawable/img_default_profile"
app:layout_constraintStart_toStartOf="@+id/days_graph"
app:layout_constraintEnd_toEndOf="@+id/days_graph"
app:layout_constraintTop_toTopOf="@+id/days_graph"
app:layout_constraintBottom_toBottomOf="@+id/days_graph"/>
<ImageView
android:id="@+id/circle_profile_overlay"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_gravity="center"
android:alpha="1"
android:contentDescription="Profile"
android:scaleType="fitCenter"
android:src="@drawable/ic_check_circle"
android:elevation="2dp"
app:layout_constraintStart_toStartOf="@+id/days_graph"
app:layout_constraintEnd_toEndOf="@+id/days_graph"
app:layout_constraintTop_toTopOf="@+id/days_graph"
app:layout_constraintBottom_toBottomOf="@+id/days_graph" />
<TextView
android:id="@+id/graph_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:bufferType="spannable"
android:text="30/365"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />
<TextView
android:id="@+id/change_info"
android:layout_width="0dp"
android:layout_height="0dp"
android:visibility="gone"/>
</androidx.constraintlayout.widget.ConstraintLayout>
xml/main_motion.xml
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2018 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:motion="http://schemas.android.com/apk/res-auto">
<Transition
motion:constraintSetStart="@layout/main_motion_start"
motion:constraintSetEnd="@layout/main_motion_end"
motion:duration="1000"
motion:onTouchUp="stop"
motion:motionInterpolator="linear">
</Transition>
</MotionScene>