android - 使用 CardsLib 库不加载带有图像的 Material 卡

标签 android android-studio cardslib

我在我的 Android 应用程序中使用 CardsLib 库。我正在尝试使用此库中的 MaterialCard。但是,当我尝试运行示例时

Material With TextAction

,我得到了这个输出

Output in my program

下面是这个 Activity 的代码:

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>

最佳答案

哈哈,只需要在 Java 代码之后添加两行:

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

关于android - 使用 CardsLib 库不加载带有图像的 Material 卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40433995/

相关文章:

java - Android 图像背景带圆角

android - 我在android studio中收到以下错误:java.util.concurrent.ExecutionException:com.android.builder.internal.aapt.AaptException:

android-studio - Android Studio : cursor lost

android - 将 Cardslib 库添加到 Android Studio 0.8.1

android - 所有 com.android.support 库必须使用准确的版本

android - 在 Android 中的串行蓝牙打印机上打印位图

java - 如何在 Android 中禁用触摸监听器一段时间

android - 创建圆形启动器图标

java - 在现有 Eclipse Android 项目中使用 cardslib 时出现问题