2016-10-05 25 views
0

CardViewの3つを作成しようとしていて、それぞれにImageViewTextViewが含まれています。私はRecyclerViewを使用していないので、私はいつもこれらの3つを持っています。CardViewsしかし、テキストのようなCardViewの内容はなぜプレビューとアプリの両方に表示されていますか?Android - CardViewのコンテンツが表示されない

これは私が得るものである:ここでは enter image description here

は、活動のための私のXMLコードです。私はstrings.xmlに対応する値を設定しました。

あなたが 、0dp、ないmatch_parentするのLinearLayoutに高さを設定する必要があり、また、あなたがそれを変更する必要がありますので、各CardViewの最後のTextViewが、0の高さに設定されている、あなたは上のLinearLayout内部の重みを使用することはできませんが、
<?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> 
+1

線形レイアウトとテキストビューの高さを設定します。android:layout_height = "0dp"でコンテンツを囲みます。 –

+0

スクロールビューをネストされたスクロールビューに変更してみてください。カードビューの周りの線形レイアウトを削除することもできます。余白なしでマージンを取ることができます。 –

+0

@KevinCrainありがとうございます。 – Yankee

答えて

2

それ以外の線形レイアウト内にない場合

+0

LinearLayout内のウェイトの使用に関する情報をありがとう。 – Yankee

関連する問題