Click here to Skip to main content
15,907,497 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I'am creating a simple clock widget in android, and I want the clock to be in a circle shape.
I defined the appwidgetprovider
XML
<?xml version="1.0" encoding="utf-8"?> <appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" android:initialLayout="@layout/clock__widget" android:minHeight="146dp" android:minWidth="146dp" android:minResizeHeight="146dp" android:minResizeWidth="146dp" android:previewImage="@drawable/example_appwidget_preview" android:resizeMode="horizontal|vertical" android:updatePeriodMillis="1800000" android:widgetCategory="home_screen">
</appwidget-provider>

and the clock__widget.xml:
XML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/widget_background">
<TextView
    android:id="@+id/digital"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:layout_margin="8dp"
    android:textColor="#ffffff"
    android:textSize="24sp"
     />
<TextView
    android:id="@+id/date"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:layout_below="@+id/digital"
    android:textColor="#ffffff"
    android:textSize="20sp"
    />
</RelativeLayout>

and in this xml file I defined the shape which is the background for my clock:
XML
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" > <solid android:color="#2196F3" /> <stroke android:width="6dp" android:color="#FFFFFF" />
</shape>

and the problem is that the clock becomes egg shaped like in the photo below and not circled as I want to.
http://imgur.com/a/cMyXM
Can someone tell me what should I do? Any help is appreciated! If you want me to include other files like the appwidget-provider.java in this thread please let me know.

What I have tried:

I have tried to get the size of the widget and resize the shape according to the size of the widget.
Java
<pre lang="java"><pre lang="java">
protected void resize(Context context, int appWidgetId){
AppWidgetManager manager = AppWidgetManager.getInstance(context) ;
Bundle bundle;
bundle = manager.getInstance(context).getAppWidgetOptions(appWidgetId);
int min_widthdb = bundle.getInt(manager.OPTION_APPWIDGET_MIN_WIDTH);
int max_widthdb = bundle.getInt(manager.OPTION_APPWIDGET_MAX_WIDTH);
int min_heightdb = bundle.getInt(manager.OPTION_APPWIDGET_MIN_HEIGHT);
int max_heightdb = bundle.getInt(manager.OPTION_APPWIDGET_MAX_HEIGHT);
GradientDrawable dr = (GradientDrawable) Resources.getSystem().getDrawable(R.drawable.widget_background);
dr.setSize(50, 50);



}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900