我已经从 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;
}
如果您需要更多信息,请告诉我。提前致谢!