CoordinatorLayout 位置 Android
CoordinatorLayout location Android
我有一个 android 界面,使用 coordinatorLayout、AppBarLayout 和 NestedScrollView 来管理滚动操作。
Before scroll Snapshot
After scroll Snapshot
滚动后点击评论按钮,AppbarLayout如何显示到屏幕顶部?和滚动前一样。
这是我的布局:
<android.support.design.widget.CoordinatorLayout
android:id="@+id/coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#ececec">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#f7f7f7"
android:fitsSystemWindows="true"
android:minHeight="1dp"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed|enterAlwaysCollapsed">
<TextView
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="@color/color_3"
android:layout_margin="10dp"/>
<!--<include layout="@layout/wentixiangqing_dingbu_wentidaan"/>-->
</android.support.design.widget.CollapsingToolbarLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#FFF">
<View
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="star:123"
android:textColor="#797979"/>
<View
android:layout_width="30dp"
android:layout_height="3dp"
android:layout_gravity="bottom|center_horizontal"
android:background="#F00"/>
</FrameLayout>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="30dp"
android:layout_marginRight="20dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="comment:90"
android:textColor="#797979"/>
<View
android:layout_width="30dp"
android:layout_height="3dp"
android:layout_gravity="bottom|center_horizontal"
android:background="#F00"/>
</FrameLayout>
</LinearLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="40dp"
android:layout_marginTop="1dp"
android:overScrollMode="always" />
</android.support.v4.widget.NestedScrollView>
<Button
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_gravity="bottom|end"
android:text="Comment" /></android.support.design.widget.CoordinatorLayout>
如有任何建议,我们将不胜感激。
您是否在单击按钮时尝试过此代码?
AppBarLayout appBarLayout = (AppBarLayout)findViewById(R.id.appbar);
appBarLayout.setExpanded(true, true);
另请参阅:
我有一个 android 界面,使用 coordinatorLayout、AppBarLayout 和 NestedScrollView 来管理滚动操作。
Before scroll Snapshot
After scroll Snapshot
滚动后点击评论按钮,AppbarLayout如何显示到屏幕顶部?和滚动前一样。
这是我的布局:
<android.support.design.widget.CoordinatorLayout
android:id="@+id/coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#ececec">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#f7f7f7"
android:fitsSystemWindows="true"
android:minHeight="1dp"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed|enterAlwaysCollapsed">
<TextView
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="@color/color_3"
android:layout_margin="10dp"/>
<!--<include layout="@layout/wentixiangqing_dingbu_wentidaan"/>-->
</android.support.design.widget.CollapsingToolbarLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#FFF">
<View
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="star:123"
android:textColor="#797979"/>
<View
android:layout_width="30dp"
android:layout_height="3dp"
android:layout_gravity="bottom|center_horizontal"
android:background="#F00"/>
</FrameLayout>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="30dp"
android:layout_marginRight="20dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="comment:90"
android:textColor="#797979"/>
<View
android:layout_width="30dp"
android:layout_height="3dp"
android:layout_gravity="bottom|center_horizontal"
android:background="#F00"/>
</FrameLayout>
</LinearLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="40dp"
android:layout_marginTop="1dp"
android:overScrollMode="always" />
</android.support.v4.widget.NestedScrollView>
<Button
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_gravity="bottom|end"
android:text="Comment" /></android.support.design.widget.CoordinatorLayout>
如有任何建议,我们将不胜感激。
您是否在单击按钮时尝试过此代码?
AppBarLayout appBarLayout = (AppBarLayout)findViewById(R.id.appbar);
appBarLayout.setExpanded(true, true);
另请参阅: