How to design Layout for both Rectangular and Round Android Watch?

How to design Layout for both Rectangular and Round
Android Watch?

Android watches comes in two shapes, round and rectangular.Therefore
WatchViewStub is available .It is a class that can inflate a specific layout,
depending on the shape of the device’s screen.

Use WatchViewStub to inflate the view as below.

public class MainActivity extends Activity {
private RelativeLayout mRectBackground;
private RelativeLayout mRoundBackground;

public void onCreate(Bundle b) {
WatchViewStub stub = (WatchViewStub) findViewById(;
stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener()
public void onLayoutInflated(WatchViewStub stub) {
mRectBackground = (RelativeLayout)
mRoundBackground = (RelativeLayout)

In the layout file of the main activity (main_activity.xml) you may specify the
layout for each watch type as below.It will automatically pick the correct
layout as required by the device.Also design two separate layout files for
each type of shapes.In this case rect_activity_my_wear.xml and

Later if we want to animate the views as per their shapes on touch we can
have the logic as below

public void onLayoutClicked(View view) {
if (mRectBackground != null) {
// Logic for Rectangular shaped watch
if (mRoundBackground != null) {
// Logic for round shaped watch

This entry was posted in Android Apps and tagged , , . Bookmark the permalink.

Leave a Reply

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


25,128 Spam Comments Blocked so far by Spam Free Wordpress

50 2z

Please type the text above:

HTML tags are not allowed.