簡體   English   中英

將視圖粘貼到滾動視圖的底部

[英]Sticking a view to bottom of scrollview

我有一種奇怪的行為我無法弄清楚-我試圖將視圖固定在滾動視圖的底部而沒有運氣。 我已經嘗試過clipToPadding和fillViewport,但是它們都沒有幫助。 有什么幫助嗎? 我的xml布局是-

<LinearLayout>

    <FrameLayout/>
    <ScrollView>
        <LinearLayout>
            <LinearLayout/>
            <RelativeLayout/> <-- This is the problematic view
        </LinearLayout>
    </ScrollView>

</LinearLayout>

我想即使在滾動視圖短於屏幕長度時也將相對布局放到底部,當clipToPadding設置為false時,它確實適合屏幕,但是相對布局只是放置在屏幕上方的線性布局之后,我在scrollview上將fillviewport設置為true(並刪除cliptopadding),scrollview的長度比屏幕長,但無法滾動,這導致相對布局“不可見”,有什么建議嗎?

嘗試在滾動視圖中使用相對布局而不是線性布局,並將相對布局與底部對齊。 但是我不確定在有內容之后它是否會滾動。

<LinearLayout>

<FrameLayout/>
<ScrollView>
    <RelativeLayout>
        <LinearLayout android:alignParentTop="true" android:id="@+id/linearLayout" />
        <RelativeLayout android:alignParentBottom="true" android:layoutBelow="@+id/linearLayout"/> <-- This is the problematic view
    </LinearLayout>
</ScrollView>

檢查是否適合您。

您可以嘗試在ScrollView中使用ConstraintLayout:

  1. 將ScrollView中的fillviewport設置為True
  2. 最后一個元素必須附加在約束的底部
  3. 最后一個元素(最后一個元素)應該將約束設置為最后一個元素。 另外,您可以添加邊距以使此元素與最后一個元素之間的距離最小,並使用constraintVertical_bias管理其位置。

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

<androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

    … Some elements with Constraints …

    <TextView
            android:id="@+id/last_but_one_element”
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"                        
            app:layout_constraintBottom_toTopOf="@+id/some_previous_element"
            app:layout_constraintTop_toBottomOf="@+id/last_element"
            android:layout_marginBottom=“40dp"
            app:layout_constraintVertical_bias="0.1"/>

    <Button
            android:id="@+id/last_element”
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM