"ScrollView can host only one direct child"問題解決
1. 問題描述:
ScrollView作為頂層view時報錯,直接導致apk崩潰,詳細錯誤資訊如下:
ScrollView can host only one direct child
2. 分析:
從錯誤資訊ScrollView can host only one direct child
可見,是xml的錯誤,下面列出錯誤的xml檔案:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/WhiteColor"
android:scrollbars="vertical" >
<!-- =================1. image ========================= -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:paddingTop="15dip" >
<ImageView
android:id="@+id/imageView_pic"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:contentDescription="text"
android:scaleType="fitCenter"
android:src="@drawable/empty_photo" />
</LinearLayout>
<!-- ========================= 2. detail ================= -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="32dp"
android:layout_marginTop="10dp"
android:orientation="vertical" >
<TextView
android:id="@+id/text_prompt"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginLeft="5dp"
android:gravity="center"
android:text="@string/text_detail"
android:textSize="15dip" />
</LinearLayout>
<!-- ========================= 3. line ================= -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="32dp"
android:layout_marginTop="4dp"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="2dp"
android:background="@color/lightgray" />
</LinearLayout>
</ScrollView>
,這個ScrollView中包含3個LinerLayout。
3. 解決:
從錯誤資訊,我們就知道,需要scrollview不能有多個child,所以,我在3個layout外,又加了一個layout,使3個layou成為這個新加的layout的子view,問題解決。下面是正確的xml定義:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/WhiteColor"
android:scrollbars="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="15dip" >
<!-- =================1. image ========================= -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:paddingTop="15dip" >
<ImageView
android:id="@+id/imageView_pic"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:contentDescription="text"
android:scaleType="fitCenter"
android:src="@drawable/empty_photo" />
</LinearLayout>
<!-- ========================= 2. detail ================= -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="32dp"
android:layout_marginTop="10dp"
android:orientation="vertical" >
<TextView
android:id="@+id/text_prompt"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginLeft="5dp"
android:gravity="center"
android:text="@string/text_detail"
android:textSize="15dip" />
</LinearLayout>
<!-- ========================= 3. line ================= -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="32dp"
android:layout_marginTop="4dp"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="2dp"
android:background="@color/lightgray" />
</LinearLayout>
</LinearLayout>
</ScrollView>
相關文章
- 巢狀ScrollView問題解決思路巢狀View
- "Only fullscreen opaque activities can request orientation "問題再分析Opaque
- CSS E:only-childCSS
- laravel 解決 mysql only_full_group_by 問題LaravelMySql
- GCC編譯遇到“a label can only be part of a statement and a declaration is not a statement”問題GC編譯
- VirtualBox Host-only Adapter,Failed to create the host-only adapter 轉APTAI
- 問題解決:TNS-12543: TNS:destination host unreachable
- 解決 ScrollView 巢狀 RecyclerView 時,慣性滑動失效的問題View巢狀
- Only AI Flow Can Do!AI
- 問題解決zipimport.ZipImportError: can‘t decompress data; zlib not availablImportErrorAI
- 解決問題:Variable 'time_zone' can't be set to the value of 'NULL'Null
- 使用monaco編輯器 報錯Can only have one anonymous define call per script file
- Doris建立表報錯Failed to find enough host with storage medium問題解決AI
- macOS 無法sudo建立資料夾返回Read-only file system問題解決Mac
- TypeError: only integer scalar arrays can be converted to a scalar indexErrorIndex
- 題解:CF437B The Child and Set
- vegetable one(tomcat問題)Tomcat
- react native ScrollView巢狀WebView 互動問題React Native巢狀WebView
- Navicat 連線 MySQL 失敗:2002-can‘t connect to server on localhost(10061)問題解決MySqlServerlocalhost
- Mac MySQL5.7 預設開啟 ONLY_FULL_GROUP_BY 模式問題與解決方案MacMySql模式
- mac提交svn提示CHECKOUT can only be performed on a version resourceMacORM
- ScrollView巢狀ListView解決辦法以及原理View巢狀
- 【Leetcode】1180. Count Substrings with Only One Distinct LetterLeetCode
- static inner class和非static inner class的例項化問題(can only instantiate non-static inner class...)
- mac ping:can not resolve www.baidu.com:Unknown hostMacAI
- Supervisor 解決 can't find command *
- 【問題解決】java.sql.SQLException: null, message from server: “Host ‘xxx.xx.xx.xxx‘ is blocked because ofJavaSQLExceptionNullServerBloC
- React報錯之React.Children.only expected to receive single React element childReact
- 關於Warning: setState(...): Can only update a mounted or mounting component. This
- 從原理上說說ScrollView巢狀ListView的問題View巢狀
- ScrollView巢狀RecyclerView滑動衝突相關問題View巢狀
- Centos 6 DNS 配置 解決 Unknown hostCentOSDNS
- SSM+Swagger問題解決 Can‘t read swagger JSON from http://localhost:8080/xxx/swagger/api-docsSSMSwaggerJSONHTTPlocalhostAPI
- 提問題比解決問題更重要
- Android8.0適配-Only fullscreen opaque activities can request orientationAndroidOpaque
- 解決mapper重名問題APP
- 解決 Unexpectedlexicaldeclarationincaseblock的問題BloC
- 解決跨域問題跨域