How do I use ShapeDrawables?

fljohwatfljohwat USMember
edited October 2012 in Xamarin.Android

My Android friend write the following method to programatically draw a rounded rectangle with a given color behind an image

private void drawImageBackground(View reusableView, int color) {
ShapeDrawable mDrawable = new ShapeDrawable(new RoundRectShape(outerRadius, null,null));
mDrawable.getPaint().setColor(color);

View backgroundView= (View)reusableView.findViewById(R.id.viewCheckoutImageBackground); 
backgroundView.setBackgroundDrawable(mDrawable);

}

I tried to do this in MonoDroid, but it doesnt seem to know about ShapeDrawables or RoundRectShapes.

The view definition is thus:

<?xml version="1.0" encoding="utf-8"?>

<TableRow
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <FrameLayout
        android:layout_width="52dp"
        android:layout_height="52dp" >

        <View
            android:id="@+id/viewCheckoutImageBackground"
            android:layout_width="45dp"
            android:layout_height="45dp"
            android:layout_gravity="left|center_vertical"
            android:layout_marginLeft="5dp"
            android:layout_marginTop="2dp">
        </View>

        <ImageView
            android:layout_width="45dp"
            android:layout_height="45dp"
            android:layout_gravity="left|center_vertical"
            android:layout_marginLeft="5dp"
            android:layout_marginTop="2dp"
            android:src="@drawable/person" />
    </FrameLayout>

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="left|center_vertical" >

        <TableRow android:layout_width="match_parent" >
            <TextView
                android:id="@+id/checkoutName"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="5dp"
                android:text="This is a sample name"
                android:textSize="22dp" >
            </TextView>
        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <LinearLayout>
                <TextView
                 android:id="@+id/checkoutDateNoYear"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:layout_marginRight="10dp"
                 android:paddingLeft="10dp"
                 android:text="Sat, Nov 12"
                 android:textSize="16dp" >
            </TextView>

            <TextView
                 android:id="@+id/checkoutDateTime"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:layout_marginRight="10dp"
                 android:text="12:15 PM"
                 android:textSize="16dp"
                 android:textColor="@color/blue_color" >
            </TextView>

            <TextView
                 android:id="@+id/checkoutDateYear"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:layout_marginRight="10dp"
                 android:text="1999"
                 android:textSize="16dp" >
            </TextView>
            </LinearLayout>

        </TableRow>
    </TableLayout>
</TableRow>

<View
    android:layout_width="match_parent"
    android:layout_height="2dp"
    android:layout_marginTop="3dp"
    android:background="@color/blue_color" />    

How would I accomplish this task?

Sign In or Register to comment.