2017-04-04 127 views
-11

有人請告訴我如何設計一個Material設計cardviewAndroid Studio包括適配器和佈局文件? 如果有人可以請也分享源代碼。Android中的CardView佈局

+1

你的第一步應該是嘗試自己,如果你發現代碼中的任何問題,然後去計算器。 –

+1

有很多教程可用,請嘗試使用它們。 –

+1

您可以冷藏http://www.androidhive.info/2016/05/android-working-with-card-view-and-recycler-view/ –

回答

1

首先,你的gradle添加文件

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

而且在.xml文件

<android.support.v7.widget.CardView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    card_view:cardCornerRadius="3dp" 
    card_view:cardBackgroundColor="@android:color/white" 
    card_view:cardElevation="4dp" 
    card_view:cardMaxElevation="6dp"> 
</android.support.v7.widget.CardView> 
1

試試這個:

gradle這個文件:

// CardView 
    compile 'com.android.support:cardview-v7:23.3.+' 

XML文件:

<android.support.v7.widget.CardView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/cv" 
     > 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:padding="16dp" 
      > 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/person_photo" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentTop="true" 
       android:layout_marginRight="16dp" 
       /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/person_name" 
       android:layout_toRightOf="@+id/person_photo" 
       android:layout_alignParentTop="true" 
       android:textSize="30sp" 
       /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/person_age" 
       android:layout_toRightOf="@+id/person_photo" 
       android:layout_below="@+id/person_name" 
       /> 

     </RelativeLayout> 

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

類文件:

CardView cv = (CardView)findViewById(R.id.cv); 
      TextView personName = (TextView)itemView.findViewById(R.id.person_name); 
      TextView personAge = (TextView)findViewById(R.id.person_age); 
      ImageView personPhoto = (ImageView)findViewById(R.id.person_photo);