【发布时间】:2017-09-03 17:51:50
【问题描述】:
这是我的 XML 布局,名称为歌曲列表:
<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>
这是包含此布局的我的片段:
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);
如何解决这个问题?似乎一切正常,但给出错误...如果有人可以请帮助
【问题讨论】:
-
那么如何才能真正做到这种布局呢?如果你有一些解决方案请回答
-
我在 CoordinatorLayout 中添加了 NestedScrollView 但还是同样的问题
-
能理解你的意思。如果您想帮助我,请回答我的问题而不是评论,然后告诉我必须将代码更改为什么或类似的东西。 tnx
标签: android android-coordinatorlayout