2016-11-05 31 views
1

我在我的Android應用程序中使用CardsLib庫。我試圖從這個庫中使用MaterialCard。然而,當我試圖運行示例圖像沒有使用CardsLib庫加載的材料卡

Material With TextAction

,我得到這個輸出

Output in my program

以下是本次活動代碼:

MaterialActivity.java

package com.a5corp.weather; 

import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.Toast; 

import java.util.ArrayList; 

import it.gmariotti.cardslib.library.cards.actions.BaseSupplementalAction; 
import it.gmariotti.cardslib.library.cards.actions.TextSupplementalAction; 
import it.gmariotti.cardslib.library.cards.material.MaterialLargeImageCard; 
import it.gmariotti.cardslib.library.internal.Card; 

public class MaterialActivity extends AppCompatActivity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_material); 

    ArrayList<BaseSupplementalAction> actions = new ArrayList<>(); 

    // Set supplemental actions 
    TextSupplementalAction t1 = new TextSupplementalAction(this, R.id.text1); 
    t1.setOnActionClickListener(new BaseSupplementalAction.OnActionClickListener() { 
     @Override 
     public void onClick(Card card, View view) { 
      Toast.makeText(getApplicationContext()," Click on Text SHARE ",Toast.LENGTH_SHORT).show(); 
     } 
    }); 
    actions.add(t1); 

    TextSupplementalAction t2 = new TextSupplementalAction(this, R.id.text2); 
    t2.setOnActionClickListener(new BaseSupplementalAction.OnActionClickListener() { 
     @Override 
     public void onClick(Card card, View view) { 
      Toast.makeText(getApplicationContext()," Click on Text LEARN ",Toast.LENGTH_SHORT).show(); 
     } 
    }); 
    actions.add(t2); 

    //Create a Card, set the title over the image and set the thumbnail 
    MaterialLargeImageCard card = 
      MaterialLargeImageCard.with(this) 
        .setTextOverImage("Italian Beaches") 
        .setTitle("This is my favorite local beach") 
        .setSubTitle("A wonderful place") 
        .setupSupplementalActions(R.layout.carddemo_native_material_supplemental_actions_large_icon, actions) 
        .build(); 

    card.setOnClickListener(new Card.OnCardClickListener() { 
     @Override 
     public void onClick(Card card, View view) { 
      Toast.makeText(getApplicationContext()," Click on ActionArea ",Toast.LENGTH_SHORT).show(); 
     } 
    }); 
} 
} 

activity_material.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
xmlns:card="http://schemas.android.com/apk/res-auto" 
android:id="@+id/activity_material" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
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.a5corp.weather.MaterialActivity"> 

<it.gmariotti.cardslib.library.view.CardViewNative 
    android:id="@+id/carddemo_largeimage_text" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
     card:card_layout_resourceID="@layout/native_material_largeimage_text_card" 
    style="@style/card_external" 
    /> 

carddemo_native_material_supplemental_actions_large_icon.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="horizontal" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:padding="@dimen/actions_padding" 
android:paddingLeft="@dimen/actions_padding_left" 
android:paddingRight="@dimen/actions_padding_left"> 

<TextView 
    android:id="@+id/text1" 
    android:text="SHARE" 
    android:background="?android:selectableItemBackground" 
    android:layout_width="wrap_content" 
    style="@style/card.native.actions" 
    android:layout_height="wrap_content"/> 


<TextView 
    android:id="@+id/text2" 
    android:text="LEARN MORE" 
    android:background="?android:selectableItemBackground" 
    android:textColor="#FF9800" 
    android:layout_width="wrap_content" 
    style="@style/card.native.actions" 
    android:layout_height="wrap_content"/> 

</LinearLayout> 
+0

我遇到同樣的問題。我實際上得到了一些文字。但從來沒有與MaterialLargeImageCard或SquareGridCard圖像。如果您找到解決方案,請發佈更新。 – TonyCruze

回答

1

哈哈,到Java代碼後添加只有兩個是需要行:

CardViewNative cardViewNative = findViewById(R.id.carddemo_largeimage_text); 
cardViewNative.setCard(card);