如何将表盘设置在手表中央 [英] How to set the Watchface in the center of watch
问题描述
我正在开发表盘.我们知道有圆形和方形表盘,所以我设计了表盘,使其不会在圆形手表中被裁剪.但同时我想将它设置在屏幕的中央.
所以告诉我如何将其设置在屏幕中心,而不管圆形和矩形屏幕.我已经做了所有的事情,但它似乎从屏幕的左侧开始调整自己.
<块引用>我在这里分享我的矩形布局代码
<?xml version="1.0" encoding="utf-8"?><android.support.wearable.view.BoxInsetLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"应用程序:layout_box="all"android:layout_height="match_parent"android:layout_width="match_parent"android:padding="15dp"><框架布局android:layout_width="match_parent"android:layout_height="match_parent"机器人:填充=5dp"应用程序:layout_box="all"><com.example.bilal.cutomanalogclockdemo.AnalogClock1android:id="@+id/clock" style="@style/clock"xmlns:android="http://schemas.android.com/apk/res/android"/></FrameLayout></android.support.wearable.view.BoxInsetLayout>
<块引用>
这是圆形布局
<框架布局android:layout_width="match_parent"android:layout_height="match_parent"机器人:填充=5dp"应用程序:layout_box="all"><com.example.bilal.cutomanalogclockdemo.AnalogClock1android:id="@+id/clock" style="@style/clock"xmlns:android="http://schemas.android.com/apk/res/android"/></FrameLayout></android.support.wearable.view.BoxInsetLayout>
现在请告诉我如何在中心调整它.谢谢
如果您查看 Google 提供的示例 AnalogWatchFaceService,您会看到它们通过边界宽度和高度获得 onDraw 上的中心 x/y
//找到中心.忽略窗口插图,以便在圆形手表上//下巴",表盘以整个屏幕为中心,而不仅仅是可用的//部分.浮动中心X = 宽度/2f;浮动中心Y =高度/2f;
示例:http://developer.android.com/samples/WatchFace/index.htmlhtml
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
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
这篇关于如何将表盘设置在手表中央的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!