Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Card View layout_height="wrap_content" inside scroll view not working

I have added card view inside scroll view and inside card view I have added preference fragment but it only show preference category title.

enter image description here

setting.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<com.afollestad.appthemeengine.inflation.ATEToolbar
    android:id="@+id/toolbar"
    android:background="?attr/colorPrimary"
    app:popupTheme="@style/AppTheme.PopupOverlay"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />
<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/view"
    android:layout_below="@+id/toolbar">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <android.support.v7.widget.CardView
            android:id="@+id/card_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:cardElevation="4dp"
            style="?attr/CardTheme" />
    </RelativeLayout>
</ScrollView>
</RelativeLayout>

any solution.

like image 557
Sawal Timsina Avatar asked Dec 01 '25 09:12

Sawal Timsina


1 Answers

Add android:fillViewport="true" to fill the scrollview. Also don't forget to change the height of relative layout inside scrollview. Change it to match_parent and card view's height also(match_parent).

Finally layout should be like this,

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<com.afollestad.appthemeengine.inflation.ATEToolbar
    android:id="@+id/toolbar"
    android:background="?attr/colorPrimary"
    app:popupTheme="@style/AppTheme.PopupOverlay"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />
<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/view"
    android:fillViewport="true"
    android:layout_below="@+id/toolbar">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <android.support.v7.widget.CardView
            android:id="@+id/card_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:cardElevation="4dp"
            style="?attr/CardTheme" />
    </RelativeLayout>
</ScrollView>
</RelativeLayout>
like image 157
Riyaz Ahamed Avatar answered Dec 03 '25 22:12

Riyaz Ahamed



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!