BottomSheet 中的 ListView 不滚动
ListView in BottomSheet not scrolling
为 Android API 23 及以上写作(在 API 24 和 25 上测试)。
我写了一个 XML,它试图将 ListView 放在 BottomSheet 中。当我尝试滚动我的 ListView(向任何方向)时,BottomSheet 滚动而不是 ListView。
我尝试了以下解决方法但没有成功:
我的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"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:id="@+id/refresh_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="onButtonPress"
android:text="@string/refresh_button" />
<RelativeLayout
android:id="@+id/map_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<fragment
android:id="@+id/map_fragment"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/floating_action_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="15dp"
android:layout_marginRight="15dp"
android:clickable="true"
app:srcCompat="@android:drawable/ic_menu_mylocation" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
<android.support.v4.widget.NestedScrollView
android:id="@+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="400dp"
android:background="?android:attr/windowBackground"
android:clipToPadding="true"
android:fillViewport="true"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:orientation="horizontal">
<TextView
android:id="@+id/textView11"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="16dp"
android:text="Stations"
android:textColor="#ffffff"
android:textSize="24sp" />
</LinearLayout>
<com.example.nicsutherland.stationfinder.Adapters.BottomSheetListView
android:id="@+id/list_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.design.widget.CoordinatorLayout>
我的 java class 在 onCreate() 方法中包含以下代码:
View bottomSheet = findViewById( R.id.bottom_sheet );
mBottomSheetBehavior = BottomSheetBehavior.from(bottomSheet);
mBottomSheetBehavior.setPeekHeight(300);
我怎样才能达到 ListView 独立于 BottomSheet 滚动的程度?
试试这个:
com.example.nicsutherland.stationfinder.Adapters.BottomSheetListView
android:id="@+id/list_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:nestedScrollingEnabled="true"\insert this line
/>
将 BottomSheetDialog Cancelable 设置为 false 并将 CanceledOnTouchOutside 设置为 true
bottomSheetDialog.setCancelable(false);
bottomSheetDialog.setCancelable(false);
bottomSheetDialog.setCanceledOnTouchOutside(真);
为 Android API 23 及以上写作(在 API 24 和 25 上测试)。
我写了一个 XML,它试图将 ListView 放在 BottomSheet 中。当我尝试滚动我的 ListView(向任何方向)时,BottomSheet 滚动而不是 ListView。
我尝试了以下解决方法但没有成功:
我的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"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:id="@+id/refresh_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="onButtonPress"
android:text="@string/refresh_button" />
<RelativeLayout
android:id="@+id/map_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<fragment
android:id="@+id/map_fragment"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/floating_action_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="15dp"
android:layout_marginRight="15dp"
android:clickable="true"
app:srcCompat="@android:drawable/ic_menu_mylocation" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
<android.support.v4.widget.NestedScrollView
android:id="@+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="400dp"
android:background="?android:attr/windowBackground"
android:clipToPadding="true"
android:fillViewport="true"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:orientation="horizontal">
<TextView
android:id="@+id/textView11"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="16dp"
android:text="Stations"
android:textColor="#ffffff"
android:textSize="24sp" />
</LinearLayout>
<com.example.nicsutherland.stationfinder.Adapters.BottomSheetListView
android:id="@+id/list_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.design.widget.CoordinatorLayout>
我的 java class 在 onCreate() 方法中包含以下代码:
View bottomSheet = findViewById( R.id.bottom_sheet );
mBottomSheetBehavior = BottomSheetBehavior.from(bottomSheet);
mBottomSheetBehavior.setPeekHeight(300);
我怎样才能达到 ListView 独立于 BottomSheet 滚动的程度?
试试这个:
com.example.nicsutherland.stationfinder.Adapters.BottomSheetListView
android:id="@+id/list_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:nestedScrollingEnabled="true"\insert this line
/>
将 BottomSheetDialog Cancelable 设置为 false 并将 CanceledOnTouchOutside 设置为 true
bottomSheetDialog.setCancelable(false);
bottomSheetDialog.setCancelable(false);
bottomSheetDialog.setCanceledOnTouchOutside(真);