我将为我的 android 片段使用一个库。我选择了cardlib,因为它提供了很多功能。现在,我正在尝试为片段创建一个 MaterialLargeImageCard。
在我的片段 xml 中,我添加了卡片的布局。我正在利用native material largeimage card
<FrameLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?android:attr/selectableItemBackground"
tools:context="com.example.emil.gamerzwiki.NewsFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<it.gmariotti.cardslib.library.view.CardViewNative
android:id="@+id/carddemo_largeimage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card:card_layout_resourceID="@layout/native_material_largeimage_card"
style="@style/card_external"
/>
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/games_list_recyclerView"
android:divider="@color/gw.dividerColor"
android:dividerHeight="4dp"
>
</android.support.v7.widget.RecyclerView>
</LinearLayout>
ArrayList<BaseSupplementalAction> actions = new ArrayList<BaseSupplementalAction>();
// Set supplemental actions
TextSupplementalAction t1 = new TextSupplementalAction(getActivity(), R.id.text1);
t1.setOnActionClickListener(new BaseSupplementalAction.OnActionClickListener() {
@Override
public void onClick(Card card, View view) {
Toast.makeText(getActivity()," Click on Text SHARE ",Toast.LENGTH_SHORT).show();
}
});
actions.add(t1);
TextSupplementalAction t2 = new TextSupplementalAction(getActivity(), R.id.ic1);
t2.setOnActionClickListener(new BaseSupplementalAction.OnActionClickListener() {
@Override
public void onClick(Card card, View view) {
Toast.makeText(getActivity()," 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(getActivity())
.setTextOverImage("Italian Beaches")
.setTitle("This is my favorite local beach")
.setSubTitle("A wonderful place")
.useDrawableId(R.drawable.abc_ab_share_pack_holo_light)
.setupSupplementalActions(R.layout.card_native_material_supplemental_cations_large_icon, actions)
.build();
card.setOnClickListener(new Card.OnCardClickListener() {
@Override
public void onClick(Card card, View view) {
Toast.makeText(getActivity()," Click on ActionArea ",Toast.LENGTH_SHORT).show();
}
});
当我运行应用程序时,它只显示一张空卡片。模型似乎没有连接到卡片视图,有什么方法可以连接吗?还是我做错了什么?
请帮忙谢谢!