gpt4 book ai didi

android - ScrollView 不在Android Bottom Sheet 中滚动

转载 作者:IT王子 更新时间:2023-10-28 23:30:48 27 4
gpt4 key购买 nike

我尝试了 Android 支持中的新 BottomSheet。在 BottomSheet 中,我放置了一个 TextView 和一个 ScrollViewBottomSheet 显示得很好,我发现的唯一问题是 BottomSheet 中的 ScrollView 没有滚动。每次我尝试滚动时,滚动的主要 Activity 中的布局或 BottomSheet 将状态从折叠更改为展开。

这是我的 Activity 类代码 fragment :

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();
}

这是我的布局 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:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.rapidgrowsolutions.android.MainActivity">


<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>

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

最佳答案

希望你现在明白这一点,但是将 View bottomSheet 更改为 NestedScrollView bottomSheet

关于android - ScrollView 不在Android Bottom Sheet 中滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36546822/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com