2016-03-04 94 views
0

如果我改变文本大小,它会溢出我的卡片视图如何更改cardview大小以适应当前文本视图大小?如何根据文字大小增加cardView大小?

<android.support.v7.widget.CardView 
xmlns:card_view="http://schemas.android.com/apk/res-auto" 
android:id="@+id/cardview" 
android:layout_width="match_parent" 
android:layout_height="120dp" 
card_view:cardElevation="1.5dp" 
card_view:cardCornerRadius="0dp" 
android:onClick="OnClick"> 
+1

你能请张贴布局XML?你的卡位有一个固定的大小? –

+0

是的,它确实.----- – eli

+2

为什么你不使用wrap_content? 如果你想有不同的大小,当你改变字体大小的大小,然后以编程方式更改卡片视图的大小。 –

回答

0

如果你想改变cardview的大小比根据文本尺寸比改变android:layout_height="wrap_content"

<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/cardview" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     card_view:cardCornerRadius="0dp" 
     card_view:cardElevation="1.5dp"> 

EX:我试图

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

    <android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/cardview" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     card_view:cardBackgroundColor="#85c7dc" 
     card_view:cardCornerRadius="0dp" 
     card_view:cardElevation="1.5dp"> 

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

      <TextView 
       android:id="@+id/txtDrVisit_DrName" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:gravity="center" 
       android:text="ABC" 
       android:textSize="25sp" 
       android:textStyle="bold" /> 

      <TextView 
       android:id="@+id/txtDrVisit_DrDetails" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:gravity="center" 
       android:text="ABC" 
       android:textSize="45sp" 
       android:textStyle="normal" /> 
     </LinearLayout> 

    </android.support.v7.widget.CardView> 
</LinearLayout>