2017-09-11 105 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