appBarLayout在启动活动时立即关闭

时间:2017-08-01 16:26:44

标签: android android-appbarlayout

我是android新手。我的一个活动有一个appbarLayout,问题是当启动该活动时,应用程序barLayout立即关闭,我必须向下滚动再次打开它。我也设置app:expaned to true,但它不适合我。 我的代码:

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/mygray">

<android.support.design.widget.AppBarLayout
    android:id="@+id/appBarLayout"
    android:layout_width="match_parent"
    android:layout_height="@dimen/appbar_h"
    app:expanded="true">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsingToolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipToPadding="true"
        android:foregroundGravity="bottom|right"
        android:foregroundTintMode="add"
        app:contentScrim="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        app:expandedTitleTextAppearance="@style/CustomToolbar">


        <com.github.mikephil.charting.charts.LineChart
            android:id="@+id/graph"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@id/toolbar"
            android:background="@color/lime300"
            app:layout_collapseMode="parallax"></com.github.mikephil.charting.charts.LineChart>

        <android.support.v7.widget.Toolbar
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:elevation="@dimen/elevation"
            app:layout_collapseMode="pin"
            app:theme="@style/Toolbar">
        </android.support.v7.widget.Toolbar>

        <TextView
            android:id="@+id/Mn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:layout_marginBottom="70dp"
            android:rotation="-90"
            android:text="بار محوری (KN)"
            android:textSize="@dimen/textsize_checkBox"
            android:textColor="@color/gray_heavy"/>
        <TextView
            android:id="@+id/Pn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/margin4"
            android:layout_marginStart="@dimen/margin4"
            android:layout_gravity="bottom"
            android:layout_marginBottom="@dimen/margin_columnAnalysis"
            android:text="لنگر خمشی (KN.m)"
            android:textSize="@dimen/textsize_checkBox"
            android:textColor="@color/gray_heavy"/>


    </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>

<include layout="@layout/nested_scroll_view"/>

 </android.support.design.widget.CoordinatorLayout>

when start the activity

after scroll sown the appBarLyout

1 个答案:

答案 0 :(得分:0)

我有同样的问题。问题是AppBarLayout下的东西(在我的应用程序片段中)向上推动AppBarLayout并关闭它,因为它的内容比可见空间填充更多。但我发现没有办法阻止这种情况......

当我隐藏片段内容时,AppbarLayout保持打开状态。

android:visibility="invisible"

更新:

我找到了解决方案:

视图中的一个元素正在获得焦点(可能是EditText)。

为了防止我的应用程序中的Collapsing,我必须将此语句放在EditText的XML中

android:focusable="false"

如果您想使用EditText,请使用onCreate:

EditText text = findViewById(R.id.textEdit);
text.setFocusable(true);

更新2:

另外,您可能需要恢复可编辑性:

text.setFocusableInTouchMode(true);
相关问题