Android - 未显示CardView内容

时间:2016-10-05 08:41:10

标签: android xml layout android-cardview cardview

我正在尝试创建三个CardView,每个ImageView包含一些TextViewRecyclerView。我没有使用CardViews,因为我在该活动中始终会有这3个CardView。但为什么strings.xml的内容如文本显示(在预览和应用程序中)?

这就是我得到的: enter image description here

这是我的活动XML代码。我在<?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.yankee.cw.ll_home"> <android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto" app:cardUseCompatPadding="true" android:id="@+id/card_view0" android:layout_gravity="center" android:padding="16dp" android:clickable="true" card_view:contentPadding="24dp" android:foreground="?android:attr/selectableItemBackground" android:layout_width="match_parent" android:layout_height="200dp" card_view:cardBackgroundColor="@color/cardview_light_background" card_view:cardElevation="@dimen/cardview_default_elevation" card_view:cardCornerRadius="4dp"> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:weightSum="1" android:layout_height="0dp"> <ImageView android:layout_width="0dp" android:layout_weight="0.15" android:layout_height="match_parent" /> <TextView android:layout_width="0dp" android:layout_weight="0.70" android:layout_gravity="center" android:textAllCaps="true" android:text="@string/ll_home_card_title_1" android:layout_height="match_parent" /> <ImageView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="0.15"/> </LinearLayout> <TextView android:layout_width="match_parent" android:text="@string/ll_home_card_content_1" android:layout_height="0dp" /> </android.support.v7.widget.CardView> <android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto" app:cardUseCompatPadding="true" android:id="@+id/card_view1" android:layout_gravity="center" android:padding="16dp" android:clickable="true" android:foreground="?android:attr/selectableItemBackground" android:layout_width="match_parent" android:layout_height="200dp" card_view:cardBackgroundColor="@color/cardview_light_background" card_view:cardElevation="@dimen/cardview_default_elevation" card_view:cardCornerRadius="4dp"> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:weightSum="1" android:layout_height="0dp"> <ImageView android:layout_width="0dp" android:layout_weight="0.15" android:layout_height="match_parent" /> <TextView android:layout_width="0dp" android:layout_weight="0.70" android:layout_gravity="center" android:textAllCaps="true" android:text="@string/ll_home_card_title_2" android:layout_height="match_parent" /> <ImageView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="0.15"/> </LinearLayout> <TextView android:layout_width="match_parent" android:text="@string/ll_home_card_content_2" android:layout_height="0dp" /> </android.support.v7.widget.CardView> <android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto" app:cardUseCompatPadding="true" android:id="@+id/card_view2" android:layout_gravity="center" android:clickable="true" android:foreground="?android:attr/selectableItemBackground" android:padding="16dp" android:layout_width="match_parent" android:layout_height="200dp" card_view:cardBackgroundColor="@color/cardview_light_background" card_view:cardCornerRadius="4dp"> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:weightSum="1" android:layout_height="0dp"> <ImageView android:layout_width="0dp" android:layout_weight="0.15" android:layout_height="match_parent" /> <TextView android:layout_width="0dp" android:layout_weight="0.70" android:layout_gravity="center" android:textAllCaps="true" android:text="@string/ll_home_card_title_3" android:layout_height="match_parent" /> <ImageView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="0.15"/> </LinearLayout> <TextView android:layout_width="match_parent" android:text="@string/ll_home_card_content_3" android:layout_height="0dp" /> </android.support.v7.widget.CardView> </LinearLayout> </ScrollView> 中设置了相应的值。

~/.m2/repository

1 个答案:

答案 0 :(得分:2)

你需要在LinearLayout中将height设置为match_parent,而不是0dp, 并且每个CardView中的最后一个TextView设置为0高度,因此您应该更改它,您可以在LinearLayout中使用权重但不能在其上使用权重(除非它在其他线性布局内)