Android-一句代碼讓NestedScrollView的布局撐滿(mǎn)屏幕

圖片來(lái)源于網(wǎng)絡(luò)

最近在使用NestedScrollView的時(shí)候想要讓布局撐滿(mǎn)撐滿(mǎn)整個(gè)屏幕,因?yàn)槲矣幸粋€(gè)控件是在屏幕底部的。我一開(kāi)始以為寫(xiě)match_parent屬性是可以達(dá)到我想要的效果,嘗試一下發(fā)現(xiàn)沒(méi)有辦法實(shí)現(xiàn)。

一句XML代碼

android:fillViewport="true" 

就是這一句代碼可以實(shí)現(xiàn)我們的需求,讓NestedScrollView里面的布局撐滿(mǎn)整屏幕。

一個(gè)XML示例

<androidx.core.widget.NestedScrollView 
        android:layout_width="match_parent"                 
        android:layout_height="match_parent"    
        android:fillViewport="true"   
        android:overScrollMode="never">
        
        <androidx.constraintlayout.widget.ConstraintLayout          
            android:layout_width="match_parent"         
            android:layout_height="match_parent"    
            android:background="@color/white">

            ......
        
    </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>

這是一個(gè)簡(jiǎn)單的使用舉例,希望對(duì)同樣使用NestedScrollView控件的小伙伴有所幫助。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容