2016-10-05 2 views
0

CardView 세 개를 만들고 각각에 ImageViewTextView이 포함되어 있습니다. 나는 항상이 활동에 RecyclerView을 사용하고 있기 때문에 나는이 3 개의 CardViews을 항상 가지고있을 것이다. 그런데 텍스트와 같은 CardView의 콘텐츠가 미리보기와 앱 모두에 표시되는 이유는 무엇입니까? enter image description hereAndroid - CardView 내용이 표시되지 않습니다.

여기 활동에 대한 내 XML 코드 :

이 내가 무엇을 얻을 수 있습니다. strings.xml에 해당 값을 설정했습니다. 당신이 아니라에있는 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

scrollview를 nestedscrollview로 변경해보십시오. 카드보기 주위의 선형 레이아웃을 제거 할 수도 있습니다. 패딩없이 마진을 얻을 수 있습니다. –

+0

@KevinCrain 감사합니다. 알았습니다. – Yankee

답변

2

당신은, match_parent, 를 0dp 및 각 CardView의 마지막 텍스트 뷰가 0 높이로 설정되어하지의 LinearLayout의 높이를 설정해야합니다, 그래서 당신은 그것을 변경해야 (다른 선형 레이아웃 내부에 있지 않는 한)

+0

LinearLayout 내부의 가중치 사용에 대한 정보를 보내 주셔서 감사합니다. – Yankee

관련 문제