简体   繁体   中英

Android AnalogClock : setting drawables programmatically

I'm making an analog clock app which has around 15 designs in one app. One way of setting the designs would be to create different widgetconfigs.XML for each design but that'll clutter up devices running 4.0+.

I also thought of setting up an activity which allows changing of the design using

remoteviews.setInt(R.id.analogClock1, "setDialResource", R.drawable.clock1);

But this won't allow the hand drawables to be set... What else can I do?

you actualy draw drawables once(when activity starts) of course there is some animations and alot of thing that change the look of activity but not drawables you can use drawable for different objects in activity like having one style for each button but you can not redraw.

you have 2 ways to do this project:

1.using XMLs

you can make 15 diffrent activities and by Intent you can switch between activities

public void method()
{
    Intent i = new Intent(this , Destination.class);
    startActivity(i);
}

2.using codes

anything that can be designed using XMLs also can be written via java codes. it takes more lines but it can be dynamic it means you don't have to make if else for each condition ; you simply produce needed objects each time it is needed .

examples:

Xml

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_text"
... />

or programmatically:

Button button = new Button(this); YourView.addview(button);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM