Android ScrollView只能添加一個(gè)子控件問(wèn)題解決方法
本文實(shí)例講述了Android ScrollView只能添加一個(gè)子控件問(wèn)題解決方法。分享給大家供大家參考,具體如下:
有下面一段代碼
<?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)為沒(méi)有什么問(wèn)題,那么我們運(yùn)行一下看看
出現(xiàn)了一個(gè)異常

很明顯,異常告訴我們ScrollView can host only one direct child
既然說(shuō)只能容納一個(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開(kāi)發(fā)入門與進(jìn)階教程》、《Android多媒體操作技巧匯總(音頻,視頻,錄音等)》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)》
希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。
- Android中ScrollView實(shí)現(xiàn)滑動(dòng)距離監(jiān)聽(tīng)器的方法
- Android StickListView實(shí)現(xiàn)懸停效果
- Android中HorizontalScrollView使用方法詳解
- Android編程開(kāi)發(fā)ScrollView中ViewPager無(wú)法正常滑動(dòng)問(wèn)題解決方法
- Android控件之ScrollView用法實(shí)例分析
- Android中實(shí)現(xiàn)監(jiān)聽(tīng)ScrollView滑動(dòng)事件
- Android中使用ScrollView指定view的頂部懸停效果
相關(guān)文章
Android實(shí)現(xiàn)掃一掃識(shí)別數(shù)字功能
這篇文章主要介紹了Android實(shí)現(xiàn)掃一掃識(shí)別數(shù)字功能,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2017-09-09
Android中使用SeekBar拖動(dòng)條實(shí)現(xiàn)改變圖片透明度(代碼實(shí)現(xiàn))
這篇文章主要介紹了Android中使用SeekBar拖動(dòng)條實(shí)現(xiàn)改變圖片透明度,需要的朋友可以參考下2020-01-01
Android開(kāi)發(fā)技巧之像QQ一樣輸入文字和表情圖像
QQ聊天輸入框,在輸入框中可以同時(shí)輸入文字和表情圖像。實(shí)際上,這種效果在Android SDK中只需要幾行代碼就可以實(shí)現(xiàn),本文將會(huì)介紹如何實(shí)現(xiàn)像QQ一樣輸入表情圖像2013-01-01
Android FlowLayout流式布局實(shí)現(xiàn)詳解
這篇文章主要為大家詳細(xì)介紹了Android FlowLayout流式布局的實(shí)現(xiàn)方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-09-09
Android 游戲引擎libgdx 資源加載進(jìn)度百分比顯示案例分析
因?yàn)榘咐容^簡(jiǎn)單,所以簡(jiǎn)單用AndroidApplication -> Game -> Stage 搭建框架感興趣的朋友可以參考下2013-01-01
Android使用fragment實(shí)現(xiàn)左側(cè)導(dǎo)航
這篇文章主要為大家詳細(xì)介紹了Android使用fragment實(shí)現(xiàn)左側(cè)導(dǎo)航,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-02-02
Kotlin中的密封類和密封接口及其應(yīng)用場(chǎng)景
在Kotlin中,密封類和密封接口是用于表示受限類型層次結(jié)構(gòu)的特殊類和接口。密封類和密封接口可以在一定程度上限制類型的繼承層次,使編譯器能夠更好地檢測(cè)代碼中的錯(cuò)誤,并增強(qiáng)代碼的可讀性和可維護(hù)性2023-05-05
Android碎片fragment實(shí)現(xiàn)靜態(tài)加載的實(shí)例代碼
這篇文章主要介紹了Android碎片fragment實(shí)現(xiàn)靜態(tài)加載的實(shí)例代碼,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-11-11
Android 中SP與DP的區(qū)別實(shí)例詳解
這篇文章主要介紹了Android 中SP與DP的區(qū)別實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下2016-10-10
Android Intent發(fā)送廣播消息實(shí)例詳解
這篇文章主要介紹了Android Intent發(fā)送廣播消息實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下2017-04-04

