2017-09-11 46 views
-5

我用这个source为我的应用程序,但有两个问题。android ViewPager问题

  1. 不能使用的按钮用于启动活动:

  2. 无法为每个卡使用图片:

mCardAdapter.addCardItem(new CardItem(R.string.title_1, R.string.title_1)); 我想使用的图片为第二个参数。

我该怎么做?

回答

0
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/card_view" 
android:layout_width="match_parent" 
android:layout_height="380dp" 
android:layout_margin="8dp"> 
<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <ImageView 
     android:id="@+id/thumbnail" 
     android:layout_width="match_parent" 
     android:layout_height="250dp" 
     android:layout_alignParentTop="true" 
     android:scaleType="centerCrop" 
     android:src="@drawable/wallpaper" /> 
    <TextView 
     android:id="@+id/title" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/thumbnail" 
     android:maxLines="3" 
     android:padding="8dp" 
     android:text="@string/title" 
     android:textColor="#222" 
     android:textStyle="bold" 
     android:textSize="22dp" /> 
</RelativeLayout> 

如果你有这样的cardview,你只需要设置的ImageView和TextView的。如果您需要更多信息,请点击此tutorial