Android CardsUILib

I recently searched for a Google Now Card library and I found CardsUILib. But I wanted a card with a picture, so I can use it in my quiz app. So I edited the whole library a bit and the result is that:

It’s a great library with a lot of potential. I did a pull request for a picture card. You can find the library here: https://github.com/nadavfima/cardsui-for-android/tree/master/CardsUILib

The edit was real easy, I created a new XML-File:

...

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/selectable_background_cardbank"
android:gravity="center_vertical"
android:padding="8dp" >

<ImageView
android:id="@+id/imageView1"
android:layout_width="154dp"
android:layout_height="127dp"
android:adjustViewBounds="true"
android:baselineAlignBottom="true"
android:scaleType="centerCrop"
android:src="@drawable/url1" />

<TextView
android:id="@+id/description"
style="@style/CardText"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="8dp"
android:ellipsize="end"
android:maxLines="7"
android:text="text text" />

...

And the Java class looked like that:


public class MyImageCard extends Card {

public MyImageCard(String title, int image){
 super(title, image);
}

@Override
public View getCardContent(Context context) {
 View view = LayoutInflater.from(context).inflate(R.layout.card_picture, null);
 ((TextView) view.findViewById(R.id.title)).setText(title);
 ((ImageView) view.findViewById(R.id.imageView1)).setImageResource(image);

return view;
}
}

As you see, the changes I made were real simple as you saw. But there were more in the library code. There I just added an Integer for the DrawableRessource.

Yannick Signer

 

Leave a Reply

Your email address will not be published. Required fields are marked *