"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>
相關文章
- 解決direct path read 與 direct path write問題
- 巢狀ScrollView問題解決思路巢狀View
- IMP-00013: only a DBA can import a file exported by another DBA 問題及解決方案ImportExport
- jQuery :only-childjQuery
- "Only fullscreen opaque activities can request orientation "問題再分析Opaque
- 解決can't find -lGL的問題
- 解決Can not allocate log問題的方法
- laravel 解決 mysql only_full_group_by 問題LaravelMySql
- CSS E:only-childCSS
- 【Ubuntu】unknown host問題解決辦法Ubuntu
- REMOTE HOST IDENTIFICATION HAS CHANGED 問題解決REMIDE
- Only a type can be imported. classname resolves to a package的解決ImportPackage
- 解決ScrollView巢狀RecyclerView滑動卡頓問題View巢狀
- 四種方案解決ScrollView巢狀ListView問題View巢狀
- GCC編譯遇到“a label can only be part of a statement and a declaration is not a statement”問題GC編譯
- 解決Android 8 0的Only fullscreen opaque activities can request orientatioAndroidOpaque
- linux上“rman can't open target”問題解決Linux
- VirtualBox Host-only Adapter,Failed to create the host-only adapter 轉APTAI
- 解決問題:Variable 'time_zone' can't be set to the value of 'NULL'Null
- 使用monaco編輯器 報錯Can only have one anonymous define call per script file
- 解決 ScrollView 巢狀 RecyclerView 時,慣性滑動失效的問題View巢狀
- 解決ScrollView巢狀ViewPager出現的滑動衝突問題巢狀Viewpager
- 解決drbd不能啟動問題(Can not load the drbd module.)
- "locate: can not open `/var/lib/mlocate/mlocate.db"問題解決
- Doris建立表報錯Failed to find enough host with storage medium問題解決AI
- 問題解決:TNS-12543: TNS:destination host unreachable
- 解決「問題」,不要解決問題
- Can one rename a database user (schema)?Database
- 問題解決zipimport.ZipImportError: can‘t decompress data; zlib not availablImportErrorAI
- python報錯問題解決:'ascii' codec can't encode characterPythonASCII
- for public synonym, only sys user can compile it?Compile
- Android -下拉重新整理,ViewPager和ScrollView巢狀滾動問題解決方案AndroidViewpager巢狀
- scrollview 套gridview的問題View
- 【linux】Can't connect to MySQL server on 'XXX' (13)問題解決方式LinuxMySqlServer
- 解決問題
- macOS 無法sudo建立資料夾返回Read-only file system問題解決Mac
- Mac MySQL5.7 預設開啟 ONLY_FULL_GROUP_BY 模式問題與解決方案MacMySql模式
- Vmware 網路模式Bridge, NAT, Host-only 以及設定host通過127.0.0.1訪問vm web server模式127.0.0.1WebServer