2017-08-01 9 views
2

私はアンドロイドで新しいです。私のアクティビティの1つにappbarLayoutがあります。問題は、そのアクティビティを開始するときに、アプリケーションbarLayoutがすぐに閉じられ、もう一度開くためにスクロールする必要があることです。私はまたapp:expanedをtrueに設定しましたが、それは私のためにはうまくいきません。 私のコード:アクティビティを開始すると、appBarLayoutは即時に閉じられます。

<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の下のもの(私のApp the Fragmentの中のもの)がAppBarLayoutをプッシュアップし、その内容が目に見える空間よりもいっぱいになっているために閉じてしまうことです。しかし、私はこれを防ぐための解決策を見つけました...

私の断片の内容を隠すと、AppbarLayoutは開いたままです。

android:visibility="invisible" 

UPDATE:

私は解決策を見つけた:あなたのビューで

1つの要素が焦点(おそらくのEditText)になっています。

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

はのonCreateで使用し、私はあなたがのEditTextを使用する場合のEditText

android:focusable="false" 

にXMLでこの文を入れていた私のアプリで崩壊を防ぐために更新2:

さらに編集可能性を戻す必要があります。

text.setFocusableInTouchMode(true); 
関連する問題