修改 - 我想这个结构我认为有点奇怪,所以我决定不这样编码,只是按照库所说的规则。(使用1个片段,然后它) -
我正在使用Board Library(参考:https://github.com/woxblom/DragListView)
board_layout.xml(Root Fragment)
<?xml version="1.0" encoding="utf-8"?>
<com.woxthebox.draglistview.BoardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/board_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/viewPager"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:clipToPadding="false"
android:overScrollMode="never"
android:paddingBottom="30dp"
android:paddingEnd="@dimen/card_padding"
android:paddingLeft="@dimen/card_padding"
android:paddingRight="@dimen/card_padding"
android:paddingStart="@dimen/card_padding" >
</android.support.v4.view.ViewPager>
</com.woxthebox.draglistview.BoardView>
fragment_adapter.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
app:cardUseCompatPadding="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:textSize="20dp"
android:text="Story Id :"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/txt_story_id"
android:text="-1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:textSize="20dp"
android:text="Count :"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/txt_story_count"
android:text="-1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</android.support.v7.widget.CardView>
recycler_item.xml
<?xml version="1.0" encoding="utf-8"?>
<com.chauthai.swipereveallayout.SwipeRevealLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/swipe_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
app:dragEdge="right"
app:mode="same_level">
<FrameLayout
android:id="@+id/delete_layout"
android:layout_width="wrap_content"
android:layout_height="70dp"
android:background="#ffcc0000">
<TextView
android:layout_width="70dp"
android:layout_height="match_parent"
android:gravity="center"
android:background="@android:color/holo_red_dark"
android:textColor="@android:color/white"
android:text="Delete"/>
</FrameLayout>
<FrameLayout
android:id="@+id/front_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffb9b9">
<include layout="@layout/vertical_recycler_item" />
</FrameLayout>
</com.chauthai.swipereveallayout.SwipeRevealLayout>
vertical_recycler_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/card"
android:padding="10dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/txt_blood_type"
android:text="bloodType"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/txt_gender"
android:text="gender"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/txt_hobby"
android:text="hobby"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:visibility="gone"
android:src="@android:drawable/ic_notification_overlay"
android:id="@+id/arrow_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/txt_move_story"
android:visibility="gone"
android:text="move!"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
并且我将使用多个片段扩展FragmentStatePagerAdapter的viewPager。
但得到错误
Caused by: android.view.InflateException: Binary XML file line #0:
HorizontalScrollView can host only one direct child
Caused by: java.lang.IllegalStateException: HorizontalScrollView can host
only one direct child
我不知道这里有什么问题。 请帮帮我谢谢。
答案 0 :(得分:1)
HorizontalScrollView只能托管一个直接子项 - 意思是,你必须将组件添加到linearlayout / relativelayout。
HorizontalScrollView -> linearlayout/relativelayout -> then components
即 BoardView - &gt; linearlayout / relativelayout - &gt; viewpager 强>
答案 1 :(得分:0)
Caused by: android.view.InflateException: Binary XML file line #0: HorizontalScrollView can host only one direct child
BoardView extends HorizontalScrollView
,因此您无法在其中添加多个子项
HorizontalScrollView
只能容纳一个直接孩子 因此,您需要使用单一布局,因为BoardView
的孩子可能是linearlayout or relativelayout
示例代码
<?xml version="1.0" encoding="utf-8"?>
<com.woxthebox.draglistview.BoardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/board_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="vertical">
//add your control here
</LinearLayout>
</com.woxthebox.draglistview.BoardView>