###環境
AndroidStudio2.3.3でJAVAを使いAndroidアプリを開発しています。
###発生している問題
BottomSheetBehaviorの状態を取得して状態によってFABをhideするコードを書いたのに、実行してもFABがhideされない状態です。f
下がそのコードでその下がレイアウトのコードです。
JAVA
1package com.example.kota327v.map; 2 3//...中略... 4 5public class MapsMain extends AppCompatActivity { 6 7 @Override 8 protected void onCreate(Bundle savedInstanceState) { 9 super.onCreate(savedInstanceState); 10 setContentView(R.layout.activity_maps_main); 11 12 final FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); 13 fab.show(); 14 BottomSheetBehavior behavior = BottomSheetBehavior.from(findViewById(R.id.bottom_sheet)); 15 behavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() { 16 17 @Override public void onStateChanged(View bottomSheet, int newState) { 18 switch (newState) { 19 case BottomSheetBehavior.STATE_DRAGGING: 20 break; 21 case BottomSheetBehavior.STATE_SETTLING: 22 break; 23 case BottomSheetBehavior.STATE_EXPANDED: 24 break; 25 case BottomSheetBehavior.STATE_COLLAPSED: 26 fab.hide(); //ここ 27 break; 28 case BottomSheetBehavior.STATE_HIDDEN: 29 break; 30 } 31 } 32 33 @Override public void onSlide(View bottomSheet, float slideOffset) { 34 } 35 }); 36 } 37} 38
XML
1<?xml version="1.0" encoding="utf-8"?> 2<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:app="http://schemas.android.com/apk/res-auto" 4 xmlns:tools="http://schemas.android.com/tools" 5 android:layout_width="match_parent" 6 android:layout_height="match_parent" 7 android:fitsSystemWindows="true" 8 tools:context="com.example.kota327v.map.MapsMain"> 9 10 <LinearLayout 11 android:layout_width="match_parent" 12 android:layout_height="match_parent" 13 android:orientation="vertical" 14 > 15 <android.support.v7.widget.Toolbar 16 android:id="@+id/toolbar" 17 android:layout_height="wrap_content" 18 android:layout_width="match_parent" 19 android:minHeight="?attr/actionBarSize" 20 android:background="?attr/colorPrimary" 21 app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 22 /> 23 24 <TextView 25 android:layout_width="match_parent" 26 android:layout_height="match_parent" 27 android:text="Normal contents" 28 android:textSize="30sp" 29 /> 30 </LinearLayout> 31 <LinearLayout 32 android:id="@+id/bottom_sheet" 33 android:layout_width="match_parent" 34 android:layout_height="match_parent" 35 android:orientation="vertical" 36 app:layout_behavior="@string/bottom_sheet_behavior" 37 app:behavior_hideable="true" 38 app:behavior_peekHeight="150dp" 39 android:background="@android:color/white" 40 > 41 <TextView 42 android:layout_width="match_parent" 43 android:layout_height="match_parent" 44 android:text="BottomSheet" 45 android:textSize="30sp" 46 /> 47 </LinearLayout> 48 49 <!--ここ--> 50 <android.support.design.widget.FloatingActionButton 51 android:id="@+id/fab" 52 android:layout_width="wrap_content" 53 android:layout_height="wrap_content" 54 android:src="@mipmap/ic_launcher" 55 android:layout_margin="16dp" 56 app:layout_anchor="@id/bottom_sheet" 57 app:layout_anchorGravity="right|top" 58 /> 59 60</android.support.design.widget.CoordinatorLayout> 61
###試したこと
fab.hide()のところをfab.setVisivility(VIEW.GONE)にすると消えました(ダサい)
###補足情報
2週間前に軽く同じようなことをしたらちゃんとhideできていたような気もするので、何か設定的なのを変えたらhideができなくなるといったことを知っている方いらっしゃいましたらそれも教えてほしいです。
まだ始めたばかりなので情報が十分ではないかもしれませんが、解決方法などを知っている方いないでしょうか?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。