ScrollView嵌套LinearLayout內(nèi)容展示不全的問題

問題布局

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/title"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:background="@color/colorPrimary"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:text="title"
        android:gravity="center"
        android:textSize="22sp"
        android:textStyle="bold"/>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintTop_toBottomOf="@+id/title"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            >

            <TextView
                android:layout_width="match_parent"
                android:layout_height="55dp"
                android:gravity="center"
                android:text="first" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="55dp"
                android:gravity="center"
                android:text="2" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="55dp"
                android:gravity="center"
                android:text="3" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="55dp"
                android:gravity="center"
                android:text="4" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="55dp"
                android:gravity="center"
                android:text="5" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="55dp"
                android:gravity="center"
                android:text="6" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="55dp"
                android:gravity="center"
                android:text="7" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="55dp"
                android:gravity="center"
                android:text="8" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="55dp"
                android:gravity="center"
                android:text="9" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="55dp"
                android:gravity="center"
                android:text="10" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="55dp"
                android:gravity="center"
                android:text="11" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="55dp"
                android:gravity="center"
                android:text="12" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="55dp"
                android:gravity="center"
                android:text="13" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="55dp"
                android:gravity="center"
                android:text="14" />


            <TextView
                android:layout_width="match_parent"
                android:layout_height="55dp"
                android:gravity="center"
                android:text="15"
                />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="55dp"
                android:gravity="center"
                android:text="last"
                />


        </LinearLayout>
    </ScrollView>

</androidx.constraintlayout.widget.ConstraintLayout>

滑動到底部效果圖


image.png

最后一條數(shù)據(jù)展示不全

解決方案兩種
第一:根布局ConstraintLayout替換為LinearLayout
第二:給ScrollVIew里邊的LineaerLayout添加底部邊距(title欄多高你就設(shè)置多高),目前title欄高度為100dp影暴,那我們就設(shè)置LineaerLayout底部邊距paddingBottom="100dp"

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/title"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:background="@color/colorPrimary"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:text="title"
        android:gravity="center"
        android:textSize="22sp"
        android:textStyle="bold"/>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintTop_toBottomOf="@+id/title"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:paddingBottom="100dp"
            >

            <TextView
                android:layout_width="match_parent"
                android:layout_height="55dp"
                android:gravity="center"
                android:text="first" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="55dp"
                android:gravity="center"
                android:text="2" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="55dp"
                android:gravity="center"
                android:text="3" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="55dp"
                android:gravity="center"
                android:text="4" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="55dp"
                android:gravity="center"
                android:text="5" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="55dp"
                android:gravity="center"
                android:text="6" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="55dp"
                android:gravity="center"
                android:text="7" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="55dp"
                android:gravity="center"
                android:text="8" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="55dp"
                android:gravity="center"
                android:text="9" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="55dp"
                android:gravity="center"
                android:text="10" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="55dp"
                android:gravity="center"
                android:text="11" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="55dp"
                android:gravity="center"
                android:text="12" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="55dp"
                android:gravity="center"
                android:text="13" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="55dp"
                android:gravity="center"
                android:text="14" />


            <TextView
                android:layout_width="match_parent"
                android:layout_height="55dp"
                android:gravity="center"
                android:text="15"
                />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="55dp"
                android:gravity="center"
                android:text="last"
                />


        </LinearLayout>
    </ScrollView>

</androidx.constraintlayout.widget.ConstraintLayout>

效果圖如下


image.png
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市旗笔,隨后出現(xiàn)的幾起案子假丧,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 212,454評論 6 493
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件恕沫,死亡現(xiàn)場離奇詭異,居然都是意外死亡纱意,警方通過查閱死者的電腦和手機(jī)婶溯,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,553評論 3 385
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來偷霉,“玉大人迄委,你說我怎么就攤上這事±嗌伲” “怎么了叙身?”我有些...
    開封第一講書人閱讀 157,921評論 0 348
  • 文/不壞的土叔 我叫張陵,是天一觀的道長硫狞。 經(jīng)常有香客問我信轿,道長,這世上最難降的妖魔是什么残吩? 我笑而不...
    開封第一講書人閱讀 56,648評論 1 284
  • 正文 為了忘掉前任财忽,我火速辦了婚禮,結(jié)果婚禮上泣侮,老公的妹妹穿的比我還像新娘即彪。我一直安慰自己,他們只是感情好活尊,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,770評論 6 386
  • 文/花漫 我一把揭開白布祖凫。 她就那樣靜靜地躺著,像睡著了一般酬凳。 火紅的嫁衣襯著肌膚如雪惠况。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 49,950評論 1 291
  • 那天宁仔,我揣著相機(jī)與錄音稠屠,去河邊找鬼。 笑死,一個胖子當(dāng)著我的面吹牛权埠,可吹牛的內(nèi)容都是我干的榨了。 我是一名探鬼主播,決...
    沈念sama閱讀 39,090評論 3 410
  • 文/蒼蘭香墨 我猛地睜開眼攘蔽,長吁一口氣:“原來是場噩夢啊……” “哼龙屉!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起满俗,我...
    開封第一講書人閱讀 37,817評論 0 268
  • 序言:老撾萬榮一對情侶失蹤转捕,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后唆垃,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體五芝,經(jīng)...
    沈念sama閱讀 44,275評論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,592評論 2 327
  • 正文 我和宋清朗相戀三年辕万,在試婚紗的時候發(fā)現(xiàn)自己被綠了枢步。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 38,724評論 1 341
  • 序言:一個原本活蹦亂跳的男人離奇死亡渐尿,死狀恐怖醉途,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情砖茸,我是刑警寧澤结蟋,帶...
    沈念sama閱讀 34,409評論 4 333
  • 正文 年R本政府宣布,位于F島的核電站渔彰,受9級特大地震影響嵌屎,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜恍涂,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 40,052評論 3 316
  • 文/蒙蒙 一宝惰、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧再沧,春花似錦尼夺、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,815評論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至顷扩,卻和暖如春拐邪,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背隘截。 一陣腳步聲響...
    開封第一講書人閱讀 32,043評論 1 266
  • 我被黑心中介騙來泰國打工扎阶, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留汹胃,地道東北人。 一個月前我還...
    沈念sama閱讀 46,503評論 2 361
  • 正文 我出身青樓东臀,卻偏偏與公主長得像着饥,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子惰赋,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,627評論 2 350

推薦閱讀更多精彩內(nèi)容