2017-04-01 8 views
0

는 내가 잘 작동하는 붕괴 도구 모음을 사용하고 있습니다. 바닥 시트 뷰를 트리거 클릭하고 하단의 시트가 표시됩니다 메뉴의 아이콘이 있습니다. 다시 클릭 할 때 바닥 시트가 다시 붕괴됩니다. 여기 동일한 활동에서 축소 도구 모음 및 하단 시트보기를 사용하는 방법은 무엇입니까? 내 활동에

은에 대한 XML이다.
<?xml version="1.0" encoding="utf-8"?> 

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fitsSystemWindows="true" 
tools:context="com.example.aadesh.khabriuncle.ArticleScreenActivity"> 

<android.support.design.widget.AppBarLayout 
    android:id="@+id/appBar" 
    android:layout_width="match_parent" 
    android:layout_height="300dp" 
    android:fitsSystemWindows="true" 
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

    <android.support.design.widget.CollapsingToolbarLayout 
     android:id="@+id/collapsingToolbar" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:fitsSystemWindows="true" 
     app:contentScrim="#7fff" 
     app:expandedTitleMarginEnd="64dp" 
     app:expandedTitleMarginStart="48dp" 
     app:layout_scrollFlags="scroll|exitUntilCollapsed" 
     app:title=""> 

     <FrameLayout 
      android:id="@+id/tags_article" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_gravity="bottom" 
      android:background="#7000" 
      android:visibility="visible"> 

      <ImageView 
       android:id="@+id/toolbarImage" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:fitsSystemWindows="true" 
       android:scaleType="centerCrop" 
       app:layout_collapseMode="parallax" /> 

      <LinearLayout 
       android:id="@+id/tags" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_gravity="bottom" 
       android:background="@drawable/shape_chips" 
       android:orientation="horizontal" 
       android:visibility="gone" /> 


     </FrameLayout> 


     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbarArticleScreen" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      app:layout_collapseMode="pin" 
      app:navigationIcon="@drawable/ic_chevron_left_black_24dp" 
      app:popupTheme="@style/ThemeOverlay.AppCompat.Light"> 

     </android.support.v7.widget.Toolbar> 


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

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

<android.support.v4.widget.NestedScrollView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 

     <TextView 
      android:id="@+id/titletext" 
      style="@style/Article.title" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 

      <TextView 
       android:id="@+id/author" 
       style="@style/Article.date" 
       android:layout_width="wrap_content" 
       android:layout_height="match_parent" 
       android:layout_alignParentLeft="true" /> 

      <TextView 
       android:id="@+id/datetext" 
       style="@style/Article.date" 
       android:layout_width="wrap_content" 
       android:layout_height="match_parent" 
       android:layout_alignParentRight="true" /> 

     </RelativeLayout> 

     <WebView 
      android:id="@+id/webview" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 


    </LinearLayout> 
</android.support.v4.widget.NestedScrollView> 

<android.support.v4.widget.NestedScrollView 
    android:id="@+id/comments_bottomSheet" 
    android:layout_width="match_parent" 
    android:layout_height="250dp" 
    android:background="@color/colorAccent" 
    android:clipToPadding="true" 
    app:layout_behavior="android.support.design.widget.BottomSheetBehavior"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 

     <TextView 
      android:id="@+id/titlebottom" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:padding="16dp" 
      android:textAllCaps="true" 
      android:textSize="16sp" /> 

     <TextView 
      android:id="@+id/textbottom" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:padding="16dp" 
      android:textAllCaps="true" 
      android:textSize="12sp" /> 

    </LinearLayout> 


</android.support.v4.widget.NestedScrollView> 

이 내가 자바

public boolean onOptionsItemSelected(MenuItem item) { 

    if (item.getItemId() == R.id.comments) { 
     Log.i(TAG, "selected item is " + item); 
     if (bottomSheetBehavior.getState() != BottomSheetBehavior.STATE_EXPANDED) { 
      Log.i(TAG, "the state is " + bottomSheetBehavior.getState()); 
      bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED); 
     } else { 
      Log.i(TAG, "the state is " + bottomSheetBehavior.getState()); 
      bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); 
     } 
    } 
    return super.onOptionsItemSelected(item); 

} 

문제는 활동이 시작될 때마다 바닥 시트 뷰가 나타날 것입니다 그것을 설정하는 방법입니다. 메뉴 아이콘을 클릭해도 아무런 변화가 없습니다. 내가 표시되는 인쇄 비록 로그.

무슨 이유가 될 수 있을까?

답변

0

잘 몇 가지가 내가 올바른 방향으로 당신을 안내하기 위해 여기에 예를 줄 것이다 을 수행 할 필요가있다.

1 단계 : 편집

android:windowSoftInputMode="stateHidden|stateAlwaysHidden" 

2 단계를 추가하여 매니페스트 파일 : 놓습니다 바닥 시트 레이아웃을 활동에 대한 XML 파일에.

<RelativeLayout 
      android:id="@+id/bottom_sheet" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      app:behavior_hideable="true" 
      app:behavior_peekHeight="0dp" 
      app:layout_behavior="com.package.ui.utils.BottomSheetBehaviorStiff"> 

3 단계 : 유틸에 BottomSheetBehaviorStiff을 추가

public class BottomSheetBehaviorStiff<V extends View> extends BottomSheetBehavior<V> { 
    private boolean mAllowUserDragging = true; 

    /** 
    * Default constructor for instantiating BottomSheetBehaviors. 
    */ 
    public BottomSheetBehaviorStiff() { 
     super(); 
    } 


    public BottomSheetBehaviorStiff(Context context, AttributeSet attrs) { 
     super(context, attrs); 
    } 

    public void setAllowUserDragging(boolean allowUserDragging) { 
     mAllowUserDragging = allowUserDragging; 
    } 

    @Override 
    public boolean onInterceptTouchEvent(CoordinatorLayout parent, V child, MotionEvent event) { 
     if (!mAllowUserDragging) { 
      return false; 
     } 
     return super.onInterceptTouchEvent(parent, child, event); 
    } 
} 

4 단계 : 이제 이 당신의 활동에 초기화 :

 RelativeLayout bottomSheetLayout = (RelativeLayout) 
     findViewById(R.id.bottom_sheet); 
       bottomSheetBehaviorStiff = (BottomSheetBehaviorStiff) 

    BottomSheetBehaviorStiff.from(bottomSheetLayout); 
      bottomSheetBehaviorStiff.setAllowUserDragging(false); 
      bottomSheetBehaviorStiff.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() { 
       @Override 
       public void onStateChanged(@NonNull View bottomSheet, int newState) { 
        if (newState == BottomSheetBehavior.STATE_HIDDEN) { 
         hideKeyBoard(); 
        } 
       } 

       @Override 
       public void onSlide(@NonNull View bottomSheet, float slideOffset) { 
       } 
      });