簡體   English   中英

ScrollView無法在CardView中運行

[英]ScrollView not working inside CardView

我已經搜索過了,沒有一個答案對我有幫助。

這是我的布局xml:

<android.support.v7.widget.CardView
        android:id="@+id/layout_building"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/_8dp"
        app:layout_constraintEnd_toStartOf="@+id/scrollview_nested_fragment_container"
        app:layout_constraintHorizontal_weight="1"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/views_container">

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

        <LinearLayout
            android:id="@+id/layout_building_container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"/>

        </ScrollView>

    </android.support.v7.widget.CardView>

我通過代碼動態地將子視圖添加到我的LinearLayout 我也嘗試移動ScrollView標簽來包裝CardView但仍然沒有運氣。 這是CardView的限制還是任何人都知道這是一個有效的解決方案。

如果使用NestedScrollView會更好

NestedScrollView就像ScrollView一樣,但它支持在新舊版本的Android上充當嵌套滾動父級和子級。

<android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        //Your CHILD Layout

</android.support.v4.widget.NestedScrollView>

FYI

您可以將您的CardView放在ScrollView下。

在ScrollView中設置此屬性

android:fillViewport="true" 

並設置cardview的高度以匹配父級或固定

好的,首先感謝每一個人幫助你提出的valauble建議。 實際問題在於ConstraintLayout 所有需要做的就是在cardview中添加一個約束app:layout_constraintBottom_toBottomOf="parent"並設置android:layout_height="0dp" cardview沒有任何強制邊界。 與LinearLayout和RelativeLayout不同,LinearLayout和RelativeLayout默認強制實施其子視圖的邊界。

暫無
暫無

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

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