2017-08-01 71 views
2

我是Android新手。我的一个活动有一个appbarLayout,问题是当开始该活动时,应用程序barLayout立即关闭,我必须向下滚动才能再次打开它。我也设置了应用程序:展开为真,但它不适合我。 我的代码:当开始活动时,appBarLayout被immedaitely关闭

<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

+0

有没有解决方法? –

回答

0

我有同样的问题。问题在于AppBarLayout下的东西(在我的应用程序片段中)将AppBarLayout向上推并关闭它,因为它的内容填充的不仅仅是可见空间。但我发现没有解决方案来防止这...

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

android:visibility="invisible" 

UPDATE:

我找到了解决办法:

在你的浏览

一个元素获取焦点(可能的EditText)。

为了防止在我的应用程序陷落我如果您想使用的EditText把这个声明在XML中的EditText

android:focusable="false" 

,在的onCreate使用:

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

更新2:

此外,也许您需要获得可编辑性:

text.setFocusableInTouchMode(true);