TextView inside CardView isn't displaying

3.4k views Asked by At

When I use TextView inside CardView, the text isn't displaying in the mobile though it shows up in the preview layout. I tried removing other views and layouts but the TextView still doesn't show up. activity-about.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    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"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleMarginEnd="64dp"
            app:expandedTitleMarginStart="48dp"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:statusBarScrim="@null"
            app:title="About">

            <ImageView
                android:id="@+id/image"
                android:layout_width="match_parent"
                android:layout_height="250dp"
                android:fitsSystemWindows="true"
                android:scaleType="centerCrop"
                android:src="@drawable/beersheba"
                app:layout_collapseMode="parallax"/>


            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/AppTheme"/>
        </android.support.design.widget.CollapsingToolbarLayout>

    </android.support.design.widget.AppBarLayout>

    <android.support.v4.widget.NestedScrollView
        android:id="@+id/scroll"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipToPadding="false"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:layout_margin="10dp">

            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                tools:ignore="UnusedAttribute">
                <ImageView
                    android:id="@+id/cover"
                    android:src="@drawable/cover_one"
                    android:layout_width="match_parent"
                    android:layout_height="76dp"
                    android:scaleType="centerCrop"
                    tools:background="#80000000"
                    tools:ignore="ContentDescription" />

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

                    <de.hdodenhof.circleimageview.CircleImageView
                        android:id="@+id/circleImageView"
                        android:layout_marginTop="30dp"
                        android:layout_width="90dp"
                        android:layout_height="90dp"
                        android:layout_gravity="center_horizontal"
                        android:src="@drawable/testimony_one"
                        app:civ_border_color="#ffffff"
                        app:civ_border_width="4dp"/>
                    <TextView
                        android:id="@+id/title"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_horizontal"
                        android:layout_marginTop="8dp"
                        android:paddingLeft="16dp"
                        android:paddingRight="16dp"
                        android:textColor="@color/textColorPrimary"
                        android:textSize="22sp"
                        tools:text="@string/title_one" />
                    <TextView
                        android:id="@+id/description"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:gravity="center_horizontal"
                        android:paddingLeft="16dp"
                        android:paddingRight="16dp"
                        android:textColor="@color/textColorSecondary"
                        android:textSize="16sp"
                        tools:text="@string/description_one" />

                </LinearLayout>

            </FrameLayout>
        </android.support.v7.widget.CardView>
    </android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>

android studio preview

text doesn't appear on phone

3

There are 3 answers

2
Keshav On BEST ANSWER

Quite a silly mistake

Change this

tools:text="@string/description_one"

to

android:text="@string/description_one"
4
Moien.Dev On

Check this out it will show textview inside cardView.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:card_view="http://schemas.android.com/apk/res-auto"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">

    <android.support.v7.widget.CardView
        android:id="@+id/card_view"
        android:layout_gravity="center"
        android:layout_width="fill_parent"
        android:layout_height="100dp"
        android:layout_margin="5dp"
        card_view:cardCornerRadius="2dp"
        card_view:contentPadding="10dp">

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">

            <TextView
                android:id="@+id/textView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textStyle="bold"
                android:layout_alignParentTop="true"/>

            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:layout_below="@+id/textView"/>
        </RelativeLayout>
    </android.support.v7.widget.CardView> 
0
Dhruv Patel On

Your code is perfectly correct. But did you check for required lib dependencies? You should import both CardView and RecyclerView lib.

Use this and sync. I think it works

    compile 'com.android.support:cardview-v7:+'
    compile 'com.android.support:recyclerview-v7:+'