gpt4 book ai didi

android - BottomSheetBehavior 不是 CoordinatorLayout 的子项

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:03:19 26 4
gpt4 key购买 nike

这是我的 XML 布局,名称为歌曲列表:

enter image description here

<android.support.design.widget.CoordinatorLayout
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">

<LinearLayout
android:id="@+id/viewA"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.6"
android:background="@android:color/holo_purple"
android:orientation="horizontal"/>

<android.support.v4.widget.NestedScrollView
android:id="@+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/holo_blue_bright"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="308dp"
/>
</LinearLayout>

</android.support.v4.widget.NestedScrollView>
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:clickable="true"
android:src="@drawable/personlog"
app:layout_anchor="@id/viewA"
app:layout_anchorGravity="bottom|center"/>

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

这是我的 fragment ,其中包含此布局:

public class SongList extends Fragment {

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

View view = inflater.inflate(R.layout.songlist,container,false);

textView=(TextView)view.findViewById(R.id.txt);

View bottomSheet = view.findViewById(R.id.bottom_sheet);
BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet);
bottomSheetBehavior.setPeekHeight(200);
return view;}
}

但是午餐时应用程序给我这个错误:

java.lang.IllegalArgumentException: The view is not a child of CoordinatorLayout

从这一行:

  BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet);

如何解决这个问题?似乎一切正常但出现错误......如果有人可以帮助

最佳答案

BottomSheetBehavior

An interaction behavior plugin for a child view of CoordinatorLayout to make it work as a bottom sheet.

目前,您的底部工作表 NestedScrollViewLinearLayout 的子项。因此,只需完全删除最外层的 LinearLayout

<android.support.design.widget.CoordinatorLayout
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:id="@+id/viewA"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.6"
android:background="@android:color/holo_purple"
android:orientation="horizontal"/>

<android.support.v4.widget.NestedScrollView
android:id="@+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/holo_blue_bright"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">

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

<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="308dp" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>

<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:clickable="true"
android:src="@drawable/personlog"
app:layout_anchor="@id/viewA"
app:layout_anchorGravity="bottom|center" />
</android.support.design.widget.CoordinatorLayout>

但是现在您在尝试实现的底部工作表方面遇到了更多问题。首先,您不应该将 wrap_content 与 ScrollView 一起使用。其次,你不应该在 ScrollView 中使用 ListView ,因为它实现了自己的滚动。您可以仅使用 ListView 作为底部工作表来简化这一过程。

关于android - BottomSheetBehavior 不是 CoordinatorLayout 的子项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43293471/

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