Reputation: 77
Hy I am working on developing the watch face. As we know that there are round and square watch face so i have designed the watch face in such a way that it does not get crop in round watch . but on the same time I want to set it at the center of the screen .
so tell me how to set it in a center of screen regardless of round and rectangular screen. I have done every thing but its seems that it start adjusting itself from the left side of screen .
I am sharing my code here for Rectangular layout
<?xml version="1.0" encoding="utf-8"?>
<android.support.wearable.view.BoxInsetLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:layout_box="all"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:padding="15dp">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp"
app:layout_box="all">
<com.example.bilal.cutomanalogclockdemo.AnalogClock1
android:id="@+id/clock" style="@style/clock"
xmlns:android="http://schemas.android.com/apk/res/android"
/>
</FrameLayout>
</android.support.wearable.view.BoxInsetLayout>
and this is for round layout
<android.support.wearable.view.BoxInsetLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:layout_box="all"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:padding="15dp">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp"
app:layout_box="all">
<com.example.bilal.cutomanalogclockdemo.AnalogClock1
android:id="@+id/clock" style="@style/clock"
xmlns:android="http://schemas.android.com/apk/res/android"
/>
</FrameLayout>
</android.support.wearable.view.BoxInsetLayout>
now please tell me how to adjust it in a center . thanks
Upvotes: 0
Views: 901
Reputation: 91
If you look at the sample Google provided, AnalogWatchFaceService, you'll see that they get the center x/y on the onDraw via the bounds width and height
// Find the center. Ignore the window insets so that, on round watches with a
// "chin", the watch face is centered on the entire screen, not just the usable
// portion.
float centerX = width / 2f;
float centerY = height / 2f;
Sample: http://developer.android.com/samples/WatchFace/index.html
Upvotes: 1