Android ScrollView只能添加一個(gè)子控件問題解決方法
本文實(shí)例講述了Android ScrollView只能添加一個(gè)子控件問題解決方法。分享給大家供大家參考,具體如下:
有下面一段代碼
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ScrollView android:layout_width="fill_parent" android:layout_height="fill_parent" > <Button android:layout_width="fill_parent" android:layout_height="wrap_content" /> <Button android:layout_width="fill_parent" android:layout_height="wrap_content" /> <Button android:layout_width="fill_parent" android:layout_height="wrap_content" /> </ScrollView> </LinearLayout>
一個(gè)ScrollView里面添加了三個(gè)Button,也許你認(rèn)為沒有什么問題,那么我們運(yùn)行一下看看
出現(xiàn)了一個(gè)異常
很明顯,異常告訴我們ScrollView can host only one direct child
既然說只能容納一個(gè)直接的子控件,那么我們就可以容納多個(gè)間接的子控件,直接在這些子控件外面再套一層LinearLayout就OK了
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ScrollView android:layout_width="fill_parent" android:layout_height="fill_parent" > <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <Button android:layout_width="fill_parent" android:layout_height="wrap_content" /> <Button android:layout_width="fill_parent" android:layout_height="wrap_content" /> <Button android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout> </ScrollView> </LinearLayout>
更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android開發(fā)入門與進(jìn)階教程》、《Android多媒體操作技巧匯總(音頻,視頻,錄音等)》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)》
希望本文所述對大家Android程序設(shè)計(jì)有所幫助。
相關(guān)文章
android 捕捉異常并上傳至服務(wù)器的簡單實(shí)現(xiàn)
本篇文章主要介紹了android 捕捉異常并上傳至服務(wù)器的簡單實(shí)現(xiàn),具有一定的參考價(jià)值,有興趣的可以了解一下。2017-04-04淺談android性能優(yōu)化之啟動(dòng)過程(冷啟動(dòng)和熱啟動(dòng))
本篇文章主要介紹了淺談android性能優(yōu)化之啟動(dòng)過程(冷啟動(dòng)和熱啟動(dòng)) ,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。2017-08-08Android編程實(shí)現(xiàn)獲取多媒體庫視頻、音頻、圖片的方法
這篇文章主要介紹了Android編程實(shí)現(xiàn)獲取多媒體庫視頻、音頻、圖片的方法,涉及Android針對多媒體視頻、音頻及相關(guān)專輯圖片、縮略圖等獲取操作實(shí)現(xiàn)技巧,需要的朋友可以參考下2018-01-01XListView實(shí)現(xiàn)多條目網(wǎng)絡(luò)數(shù)據(jù)刷新加載 網(wǎng)絡(luò)加載圖片
這篇文章主要為大家詳細(xì)介紹了XListView實(shí)現(xiàn)多條目網(wǎng)絡(luò)數(shù)據(jù)刷新加載,網(wǎng)絡(luò)加載圖片,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-11-11Android系統(tǒng)進(jìn)程間通信(IPC)機(jī)制Binder中的Client獲得Server遠(yuǎn)程接口過程源代碼分析
本文主要介紹Android 通信Binder中的Client獲得Server遠(yuǎn)程接口,這里對Android Binder 中Client中Server 源碼做了詳細(xì)分析介紹,有研究Android源碼的小伙伴可以參考下2016-08-08Android搭建本地Tomcat服務(wù)器及相關(guān)配置
這篇文章主要介紹了Android搭建本地Tomcat服務(wù)器及相關(guān)配置,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-07-07Android本地?cái)?shù)據(jù)存儲Room實(shí)踐和優(yōu)化技巧
本文詳細(xì)介紹了Android本地?cái)?shù)據(jù)存儲框架Room的使用,包括基本概念、核心組件、最佳實(shí)踐、優(yōu)化技巧等,幫助開發(fā)者學(xué)習(xí)和掌握Room的使用方法,提升數(shù)據(jù)存儲效率和應(yīng)用性能2023-04-04