【问题标题】:CoordinatorLayout location AndroidCoordinatorLayout 位置 Android
【发布时间】:2017-08-23 07:21:16
【问题描述】:

我有一个 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>

任何建议都将不胜感激。

【问题讨论】:

    标签: android android-recyclerview android-coordinatorlayout


    【解决方案1】:

    您是否在单击按钮时尝试过此代码?

    AppBarLayout appBarLayout = (AppBarLayout)findViewById(R.id.appbar);
                appBarLayout.setExpanded(true, true);
    

    另见:Hide/Show Toolbar programmatically on CoordinatorLayout

    【讨论】:

    • 感谢您的建议,但它对我不起作用。我只想在用户按下评论按钮时显示 appbarlayout。
    • 你有没有把这个调用放在你按钮的点击监听器中? appBarLayout.setExpanded(true, true);
    • emmmm,对不起,我又试了一次,成功了!非常感谢您的建议!
    猜你喜欢
    • 1970-01-01
    • 2016-02-10
    • 2015-08-13
    • 2023-03-11
    • 2018-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多