gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 00:54:19 28 4
gpt4 key购买 nike

我在我的 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com