我将使用一个库来存储我的android片段。我选择了cardslib,因为它提供了很多功能。现在,我正在尝试为片段创建一个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>
在我的片段中,我根据https://github.com/gabrielemariotti/cardslib/blob/master/doc/MATERIALCARD.md#how-to-build-a-material-card-with-an-image设置了以下模型
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();
}
});当我运行应用程序时,它只显示一张空卡。似乎模型没有连接到卡片视图,有什么方法可以连接它吗?还是我做错了什么?
请帮帮忙,谢谢!
发布于 2015-02-06 17:35:51
在一些阅读之后,这可能会对某些人有所帮助,所以我会把答案贴出来
似乎我们需要通过以下方式连接卡片对象和布局
CardViewNative cardView = (CardViewNative) view.findViewById(R.id.carddemo_largeimage);
cardView.setCard(card);https://stackoverflow.com/questions/28361990
复制相似问题