ScrollView can host only one direct child

java.lang.IllegalStateException

ScrollView can host only one direct child

Description of the problem:
The layout file of the development interface is displayed on the vertical screen by default, and the function data is displayed normally. When the mobile phone is displayed on the horizontal screen, an error is reported:
ScrollView can host only one direct child. (An exception occurs when android adopts the ScrollView layout)

Problem analysis:
The main reason is that there can only be one sub-element inside the ScrollView, that is, two sub-elements cannot be juxtaposed, so all sub-elements need to be placed inside a LinearLayout or other layout methods such as RelativeLayout.

PlanA:
The Activity performs onCreate again when the screen is horizontal, resulting in adding a child element to the original scrollView again, and the program reports an error.
getSupportFragmentManager().beginTransaction().add(R.id.drillDesignQuery_scrollView, fragment).commit( )
;
The scrollView of the layout file is changed to lineout, because the RecyclerView in the fragment layout file has its own sliding function. The test is successful.
original layout file

PlanB:
The layout file is not changed, change the add in PlanA to repla

Guess you like

Origin blog.csdn.net/qq_28872655/article/details/115938109