2016-04-11 26 views
8

Tôi đã thử sử dụng BottomSheet mới trong hỗ trợ Android. Bên trong số BottomSheet Tôi đã đặt TextViewScrollView. Các BottomSheet chỉ hiển thị tốt, vấn đề duy nhất tôi thấy là ScrollView trong BottomSheet không di chuyển. Mỗi khi tôi cố gắng cuộn, bố cục trong hoạt động chính cuộn hoặc trạng thái thay đổi BottomSheet từ thu gọn để mở rộng.Chế độ xem cuộn không cuộn trong bảng tính dưới cùng của Android

đây là đoạn mã lớp Hoạt động của tôi:

private BottomSheetBehavior behavior; 
View bottomSheet; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    setTextViewOnClickListener(this, findViewById(R.id.parentLayout)); 

    CoordinatorLayout coordinatorLayout = (CoordinatorLayout) findViewById(R.id.main_content); 

    // The View with the BottomSheetBehavior 
    bottomSheet = coordinatorLayout.findViewById(R.id.bottom_sheet); 
    behavior = BottomSheetBehavior.from(bottomSheet); 
    behavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() { 
     @Override 
     public void onStateChanged(@NonNull View bottomSheet, int newState) { 
      // React to state change 


     } 


     @Override 
     public void onSlide(@NonNull View bottomSheet, float slideOffset) { 
      // React to dragging events 
     } 
    }); 

@Override 
public void onClick(View v) { 
    switch (v.getId()) { 
     case R.id.tv1: 
      setTextViewHeader("Header1"); 
      setTextViewContent("Long_Text_1"); 

      break; 

     case R.id.tv2: 
      setTextViewHeader("Header2"); 
      setTextViewContent("Long_Text_2"); 

      break; 

     case R.id.tv3: 
      setTextViewHeader("Header3"); 
      setTextViewContent("Long_Text_3"); 

      break; 

     default: 
      break; 
    } 

    behavior.setPeekHeight(100); 
    behavior.setState(BottomSheetBehavior.STATE_COLLAPSED); 
    behavior.setHideable(true); 

    bottomSheet.requestLayout(); 
} 

Đây là xml Layout của tôi:

<?xml version="1.0" encoding="utf-8"?> 

<android.support.design.widget.AppBarLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:theme="@style/AppTheme.AppBarOverlay"> 


    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" 
     app:layout_scrollFlags="scroll|enterAlways" 
     app:popupTheme="@style/AppTheme.PopupOverlay" /> 


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


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

    <TextView 
     android:id="@+id/tv1" 
     style="@style/LightRow" 
     android:text="some_long_text_here" /> 

    <TextView 
     android:id="@+id/tv2" 
     style="@style/DarkRow" 
     android:text="another_long_text_here" /> 

    <TextView 
     android:id="@+id/tv3" 
     style="@style/LightRow" 
     android:text="another_long_text_here" /> 
</LinearLayout> 

<android.support.v4.widget.NestedScrollView 
    android:id="@+id/bottom_sheet" 
    android:layout_width="match_parent" 
    android:layout_height="250dp" 
    app:behavior_hideable="true" 
    android:fillViewport="true" 
    app:layout_behavior="android.support.design.widget.BottomSheetBehavior"> 


    <android.support.v7.widget.LinearLayoutCompat 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="#FF7733" 
     android:orientation="vertical"> 


     <TextView 
      android:id="@+id/tvID1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="HEADER" 
      android:textAppearance="?android:attr/textAppearanceMedium" /> 

     <ScrollView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_weight="9" 
      android:background="#ffb773" 
      android:fillViewport="true"> 


      <TextView 
       android:id="@+id/tvID2" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="#3377ff" 
       android:textAppearance="?android:attr/textAppearanceSmall" /> 
     </ScrollView> 


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

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

Xin vui lòng giúp.

Cảm ơn

+0

Xin vui lòng gửi mã của bạn cho cách bố trí để chúng tôi có thể kiểm tra. Ngoài ra để 'ScrollView' hoạt động, nó sẽ chỉ có một phần tử con bên dưới nó. –

+0

hiển thị những gì bạn đã thử – Pooya

+0

tôi có thêm một số mã trong câu hỏi của tôi, bạn có thể vui lòng xem và đưa ra giải pháp – asiansaga

Trả lời

-1

Sử dụng dưới đây hành vi tùy chỉnh tấm đáy

public class CustomBottomSheetBehaviour<V extends View> extends BottomSheetBehavior { 
    public CustomBottomSheetBehaviour() { 
     super(); 
    } 

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

    @Override 
    public boolean onInterceptTouchEvent(CoordinatorLayout parent, View child, MotionEvent event) { 
     return false; 
    } 
} 
4

Hy vọng bạn tìm ra điều này bằng cách bây giờ, nhưng thay đổi View bottomSheet-NestedScrollView bottomSheet.

0

tôi giải quyết vấn đề này bằng cách làm dưới đây mọi thứ -

  • Đầu tiên: không sử dụng scrollview khi bạn đang sử dụng CoordinatorLayout thay vì sử dụng NestedScrollView tác phẩm của mình tốt hơn nhiều với CoordinatorLayout.

  • Thứ hai: đặt một cái nhìn trống với android:layout_height ở phía dưới, nhưng bên trong bạn NestedScrollView ví dụ -

    <LinearLayout 
        android:layout_height="wrap_content" 
        android:layout_width="match_parent" 
        android:orientation="vertical"> 
    
        <ImageView 
         android:background="@drawable/username" 
         android:id="@+id/userImage_info_search" 
         android:layout_gravity="center" 
         android:layout_height="100dp" 
         android:layout_margin="20dp" 
         android:layout_width="100dp" /> 
    
        <LinearLayout 
         android:layout_height="wrap_content" 
         android:layout_width="match_parent"> 
    
        <View 
         android:background="@android:color/black" 
         android:layout_height="1dp" 
         android:layout_width="match_parent"></View> 
    </LinearLayout> 
    
    <LinearLayout 
        android:layout_height="wrap_content" 
        android:layout_width="match_parent" 
        android:orientation="horizontal" 
        android:padding="10dp" 
        android:weightSum="3"> 
    
        <TextView 
         style="@style/Bottomsheetstyle" 
         android:id="@+id/txtNamelabel_info_search" 
         android:layout_gravity="center" 
         android:layout_height="wrap_content" 
         android:layout_marginLeft="10dp" 
         android:layout_weight="1" 
         android:layout_width="0dp" 
         android:text="Name" /> 
    
        <TextView 
         style="@style/Bottomsheetstyle" 
         android:id="@+id/txtName_info_search" 
         android:layout_gravity="center" 
         android:layout_height="wrap_content" 
         android:layout_marginLeft="10dp" 
         android:layout_weight="2" 
         android:layout_width="0dp" 
         android:text="" /> 
    
    
    </LinearLayout> 
    
    <LinearLayout 
        android:layout_height="wrap_content" 
        android:layout_width="match_parent"> 
    
        <View 
         android:background="@android:color/black" 
         android:layout_height="1dp" 
         android:layout_width="match_parent"></View> 
    </LinearLayout> 
    
    <LinearLayout 
        android:layout_height="wrap_content" 
        android:layout_width="match_parent" 
        android:orientation="horizontal" 
        android:padding="10dp" 
        android:weightSum="3"> 
    
        <TextView 
         style="@style/Bottomsheetstyle" 
         android:layout_gravity="center" 
         android:layout_height="wrap_content" 
         android:layout_marginLeft="10dp" 
         android:layout_weight="1" 
         android:layout_width="0dp" 
         android:text="Number" /> 
    
        <LinearLayout 
         android:layout_height="wrap_content" 
         android:layout_weight="2" 
         android:layout_width="0dp" 
         android:orientation="horizontal"> 
    
         <TextView 
          style="@style/Bottomsheetstyle" 
          android:gravity="center_vertical" 
          android:id="@+id/txtNumber_info_search" 
          android:layout_gravity="center_vertical" 
          android:layout_height="wrap_content" 
          android:layout_marginLeft="10dp" 
          android:layout_weight="1.4" 
          android:layout_width="0dp" 
          android:text="+XX (XXX) XXX-XXXX" /> 
    
         <ImageView 
          android:background="@drawable/call_save" 
          android:id="@+id/call_info_search" 
          android:layout_height="wrap_content" 
          android:layout_weight="0.3" 
          android:layout_width="0dp" /> 
    
         <View 
          android:layout_gravity="center" 
          android:layout_height="5dp" 
          android:layout_width="5dp"></View> 
    
         <ImageView 
          android:background="@drawable/comment_save" 
          android:id="@+id/sms_info_search" 
          android:layout_height="wrap_content" 
          android:layout_weight="0.3" 
          android:layout_width="0dp" /> 
    
    
        </LinearLayout> 
    
    
    </LinearLayout> 
    
    <LinearLayout 
        android:layout_height="wrap_content" 
        android:layout_width="match_parent"> 
    
        <View 
         android:background="@android:color/black" 
         android:layout_height="1dp" 
         android:layout_width="match_parent"></View> 
    </LinearLayout> 
    
    <LinearLayout 
        android:layout_height="wrap_content" 
        android:layout_width="match_parent" 
        android:orientation="horizontal" 
        android:padding="10dp" 
        android:weightSum="3"> 
    
        <TextView 
         style="@style/Bottomsheetstyle" 
         android:layout_gravity="center" 
         android:layout_height="wrap_content" 
         android:layout_marginLeft="10dp" 
         android:layout_weight="1" 
         android:layout_width="0dp" 
         android:text="Email" /> 
    
        <TextView 
         style="@style/Bottomsheetstyle" 
         android:id="@+id/txtEmail_info_search" 
         android:layout_gravity="center" 
         android:layout_height="wrap_content" 
         android:layout_marginLeft="10dp" 
         android:layout_weight="2" 
         android:layout_width="0dp" 
         android:text="" /> 
    
    
    </LinearLayout> 
    
    <LinearLayout 
        android:layout_height="wrap_content" 
        android:layout_width="match_parent"> 
    
        <View 
         android:background="@android:color/black" 
         android:layout_height="1dp" 
         android:layout_width="match_parent"></View> 
    </LinearLayout> 
    
    <View 
        android:background="@android:color/transparent" 
        android:layout_height="@dimen/somedp" 
        android:layout_width="match_parent" /> 
    

+0

Cách thức hoạt động? Tôi nhận được một java.lang.IllegalStateException: ScrollView có thể lưu trữ chỉ một con trực tiếp – Ruben2112

Các vấn đề liên quan