Android 如何使Cardslib库的基本材质卡在单击文本补充操作时展开
我从Github的library中实现了新的材质卡设计,并在Recycler视图中使用了多张卡。我实施的卡片布局是: 现在,当我点击卡片中的“了解更多”并在其中膨胀我的自定义布局时,我想使卡片展开。我如何实现这一点?以下是我的Android 如何使Cardslib库的基本材质卡在单击文本补充操作时展开,android,material-design,android-recyclerview,cardslib,Android,Material Design,Android Recyclerview,Cardslib,我从Github的library中实现了新的材质卡设计,并在Recycler视图中使用了多张卡。我实施的卡片布局是: 现在,当我点击卡片中的“了解更多”并在其中膨胀我的自定义布局时,我想使卡片展开。我如何实现这一点?以下是我的MainActivty.java文件中的一段代码: public class MainActivity extends ActionBarActivity { final int TOTAL_CARDS = 3; //private CardArrayAdapter
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;
}
公共类MainActivity扩展了ActionBarActivity{
最终总积分=3;
//私人卡达拉适配器
私人卡ArrayRecyclServiceAdapter mCardArrayAdapter;
私人卡回收视图mRecyclerView;
字符串名称;
串价;
int pimage[]={R.drawable.ghewar,R.drawable.icehalwa,R.drawable.khakra};
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ArrayList cards=新的ArrayList();
mCardArrayAdapter=新的CardArrayRecyclServiceAdapter(此为卡);
//交错网格视图
CardRecyclerView mRecyclerView=(CardRecyclerView)findViewById(R.id.card\u recyclerview);
mRecyclerView.setHasFixedSize(false);
mRecyclerView.setLayoutManager(新的LinearLayoutManager(this));
//设置空视图
if(mRecyclerView!=null){
mRecyclerView.setAdapter(mCardArrayAdapter);
}
//加载卡
新的LoaderAsyncTask().execute();
}
私有ArrayList initCard(){
ArrayList cards=新的ArrayList();
对于(int i=0;i
如果你需要更多的信息,一定要告诉我。提前谢谢