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