Scrollview can host only one direct child
Wrap all the children inside of another LinearLayout with wrap_content
for both the width and the height as well as the vertical orientation.
ScrollView can host only one direct child with relativelayout
The Answer given by Md.ibrahim khalil is absolutely right,
Try by replacing your layout with this,
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
//Scroll view starts here
<include
android:id="@+id/toolbar"
layout="@layout/view_toolbar" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/grey_868686">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:text="Most Download"
android:textColor="@color/white"
android:textSize="14sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:onClick="onOtherVideo"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:text="More"
android:textColor="@color/white"
android:textSize="14sp" />
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_video_terbaru"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/grey_868686">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:text="Funny Video"
android:textColor="@color/white"
android:textSize="14sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:onClick="onOtherVideoFunny"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:text="More"
android:textColor="@color/white"
android:textSize="14sp" />
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_funny_video"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/grey_868686">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:text="Religy Video"
android:textColor="@color/white"
android:textSize="14sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:onClick="onOtherReligyVideo"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:text="More"
android:textColor="@color/white"
android:textSize="14sp" />
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_religi_video"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/grey_868686">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:text="Others Video"
android:textColor="@color/white"
android:textSize="14sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:onClick="onOtherMoreVideo"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:text="More"
android:textColor="@color/white"
android:textSize="14sp" />
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_others_video"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>
</LinearLayout>
java.lang.IllegalStateException: ScrollView can host only one direct child
Just as the error says
ScrollView can host only one direct child
Wrap the View
s inside of a LinearLayout
so the ScrollView
has only the LinearLayout
as a direct child.
From the Docs
A ScrollView is a FrameLayout, meaning you should place one child in it containing the entire contents to scroll; this child may itself be a layout manager with a complex hierarchy of objects. A child that is often used is a LinearLayout in a vertical orientation, presenting a vertical array of top-level items that the user can scroll through.
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
// all the views currently in your ScrollView
</LinearLayout>
</ScrollView>
IllegalStateException : ScrollView can host only one direct child
Use Frame Layout instead of fragment in activity_details bcoz fragment is used when u have a fixed fragment to show.
Here u r showing ur movie detail fragment using it but then again u r inflating another fragment(another instance of movie detail fragment) in ur activity and creates the problem.
HorizontalScrollView can host only one direct child
Meaning, you have to add the imageview to the linearlayout. when you add the image view you are adding it to the HorizontalScrollview
which also has a LinearLayout
in it ther by adding 2 child elements to the HorizontalScrollView which you cannot do
.IllegalStateException: ScrollView can host only one direct child
No, you have one SrollView inside a LinearLayout. Your ScrollView just has a bunch of TextViews in it. Change it to this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#ffffff"
tools:context=".Blood">
<TextView
android:layout_width="wrap_content"
android:layout_height="56dp"
android:textStyle="bold"
android:background="#f4051d"
android:textAlignment="center"
android:textColor="#ffffff"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Blood Type: Facts and Information"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#ffffff"
android:padding="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/intro"
android:layout_width="wrap_content"
android:layout_marginTop="15dp"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textColor="#000000"
android:fontFamily="sans-serif-condensed"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="When "/>
<TextView
android:layout_width="wrap_content"
android:layout_marginTop="15dp"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textColor="#0e06f2"
android:fontFamily="sans-serif-condensed"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Blood Types ( Groups )"/>
<TextView
android:id="@+id/blood_types"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:fontFamily="sans-serif-condensed"
android:text="A blood "
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000"
android:textStyle="bold" />
<ImageView
android:id="@+id/image_one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/drawable_blood_one"/>
<TextView
android:id="@+id/blood_type_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:fontFamily="sans-serif-condensed"
android:text="In addition ."
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_marginTop="15dp"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textColor="#0e06f2"
android:fontFamily="sans-serif-condensed"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Donating Blood By Compatible Type"/>
<TextView
android:id="@+id/donate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:fontFamily="sans-serif-condensed"
android:text="Blood "
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000"
android:textStyle="bold" />
<ImageView
android:id="@+id/image_two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/drawable_blood_two"/>
<TextView
android:layout_width="wrap_content"
android:layout_marginTop="15dp"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textColor="#0e06f2"
android:fontFamily="sans-serif-condensed"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Finding Out Your Blood Type"/>
<TextView
android:id="@+id/find_blood_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:fontFamily="sans-serif-condensed"
android:text="It is easy "
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000"
android:textStyle="bold" />
<ImageView
android:id="@+id/image_three"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/drawable_blood_three"/>
<TextView
android:id="@+id/find_blood_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:fontFamily="sans-serif-condensed"
android:text="In most"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_marginTop="15dp"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textColor="#0e06f2"
android:fontFamily="sans-serif-condensed"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="What Does Blood Group RH Factor Mean"/>
<TextView
android:id="@+id/rh_factor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:fontFamily="sans-serif-condensed"
android:text="RH factor ."
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_marginTop="15dp"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textColor="#0e06f2"
android:fontFamily="sans-serif-condensed"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="What is the Rarest Blood Type"/>
<TextView
android:id="@+id/rare_blood"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:fontFamily="sans-serif-condensed"
android:text="According "
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_marginTop="15dp"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textColor="#0e06f2"
android:fontFamily="sans-serif-condensed"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Blood Type Diet"/>
<TextView
android:id="@+id/blood_type_diet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:fontFamily="sans-serif-condensed"
android:text=" The Ea"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_marginTop="15dp"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textColor="#0e06f2"
android:fontFamily="sans-serif-condensed"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Blood Types and Personality"/>
<TextView
android:id="@+id/personality"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:fontFamily="sans-serif-condensed"
android:text="Legend"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_marginTop="15dp"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textColor="#0e06f2"
android:fontFamily="sans-serif-condensed"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Facts: Blood Types"/>
<TextView
android:id="@+id/facts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:fontFamily="sans-serif-condensed"
android:text="Blood"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000"
android:textStyle="bold" />
</LinearLayout>
</ScrollView>
</LinearLayout>
Backstack exception ScrollView can host only one direct child
You can add a FrameLyout
as a child to NestedScrollView
and use that FrameLyout
as your container. So that the fragment view will always be added to the FrameLyout
and NestedScrollView
will only have one direct child.
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:fillViewport="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior" >
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</android.support.v4.widget.NestedScrollView>
Related Topics
Launch Activities from Different Package
Get Context of Popupmenu Like Contextmenu
How to Add to My Android Application a Button Than Do Like to a Facebook Page
How to Share Same Data Between Multiple Activities
Androidstudio Cannot Find Layout
Complete Working Sample of the Gmail Three-Fragment Animation Scenario
What Is the Purpose of Android's <Merge> Tag in Xml Layouts
Progressdialog Is Deprecated.What Is the Alternate One to Use
How to Build an Android Library with Android Studio and Gradle
Toolbar and Contextual Actionbar with Appcompat-V7
Best Practice for Nested Fragments in Android 4.0, 4.1 (<4.2) Without Using the Support Library
Simulate Low Network Connectivity for Android
Reading SQLite File from Asset Folder
Drawerlayout Double Drawer (Left and Right Drawers Simultaneously)