我已经从Github的CardsLib库中实现了新的Material Card设计,并在Recycler视图中使用了多张卡片。我实施的卡片布局是:
现在,当我点击“了解更多”时,我想让卡片展开。在卡中,并在其中膨胀我的自定义布局。我该如何实现呢?以下是我的MainActivty.java
文件中的代码段:
public class MainActivity extends ActionBarActivity {
final int TOTAL_CARDS = 3;
//private CardArrayAdapter
private CardArrayRecyclerViewAdapter mCardArrayAdapter;
private CardRecyclerView mRecyclerView;
String productname;
String price;
int pimage[]={R.drawable.ghewar,R.drawable.icehalwa,R.drawable.khakra};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ArrayList<Card> cards = new ArrayList<>();
mCardArrayAdapter = new CardArrayRecyclerViewAdapter(this, cards);
//Staggered grid view
CardRecyclerView mRecyclerView = (CardRecyclerView) findViewById(R.id.card_recyclerview);
mRecyclerView.setHasFixedSize(false);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
//Set the empty view
if (mRecyclerView != null) {
mRecyclerView.setAdapter(mCardArrayAdapter);
}
//Load cards
new LoaderAsyncTask().execute();
}
private ArrayList<Card> initCard() {
ArrayList<Card> cards = new ArrayList<Card>();
for (int i = 0; i < TOTAL_CARDS; i++) {
ArrayList<BaseSupplementalAction> actions = new ArrayList<BaseSupplementalAction>();
// Set supplemental actions
TextSupplementalAction t1 = new TextSupplementalAction(this, R.id.action1);
t1.setOnActionClickListener(new BaseSupplementalAction.OnActionClickListener() {
@Override
public void onClick(Card card, View view) {
Toast.makeText(MainActivity.this," Click on Text SHARE "+card.getTitle(),Toast.LENGTH_SHORT).show();
}
});
switch(i){
case 0: productname="Paneer Ghewar";
price="Rs 200";
break;
case 1: productname="Bombay Ice Halwa";
price="Rs 400";
break;
case 2: productname="Gujrati Khakra";
price="Rs 150";
break;
}
//Create a Card, set the title over the image and set the thumbnail
MaterialLargeImageCard card =
MaterialLargeImageCard.with(this)
.setTextOverImage(productname)
.setTitle("This is my favorite delicacy!!")
.setSubTitle(price)
.useDrawableId(pimage[i])
.setupSupplementalActions(R.layout.carddemo_native_material_supplemental_actions_large_icon, actions)
.build();
actions.add(t1);
card.build();
cards.add(card);
}
return cards;
}
如果您需要更多信息,请告诉我们。提前谢谢!