索尼SmartWatch的XML布局 [英] XML Layout on Sony Smartwatch

查看:167
本文介绍了索尼SmartWatch的XML布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有得到一个适当的布局的128×128的SmartWatch屏幕上的问题。

I am having issues getting a proper layout on the 128x128 smartwatch screen.

这是一个有趣的问题,因为对手表的布局显然是继承自它运行在设备上的屏幕像素密度。因此,在片与手机运行时对手表的布局元素的大小完全不同。

This is an interesting issue because the layout on the watch is clearly inheriting the screen density from the device it's running on. So when ran on the tablet vs the handset the layout elements on the watch are sized completely different.

我基础上的智能扩展SDK示例项目之一,我的布局。

I'm basing my layout on one of the sample projects in the smart extensions SDK.

通过这个XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="@dimen/smart_watch_control_width"
    android:layout_height="@dimen/smart_watch_control_height"
    android:id="@+id/rlayout"
>

    <Button
        android:id="@+id/imageViewUp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:tag="button"
        android:background="@drawable/up_selector" />
    ...more Buttons
</RelativeLayout>

初​​始化布局的SmartView仅仅是一个扩展的LinearLayout

Initializing the layout, SmartView is just an extended LinearLayout

private LinearLayout createLayout() {
    mSmartView = new SmartView(mContext);
    mSmartView.setLayoutParams(new LayoutParams(WIDTH, HEIGHT));

    LinearLayout sampleLayout = (LinearLayout) LinearLayout.inflate(
            mContext, R.layout.xbmc, mSmartView);

    sampleLayout.measure(WIDTH, HEIGHT);

    Log.i(TAG, "layout width: " + sampleLayout.getMeasuredWidth()
            + " height: " + sampleLayout.getMeasuredHeight());

    sampleLayout.layout(0, 0, sampleLayout.getMeasuredWidth(),
            sampleLayout.getMeasuredHeight());

    return sampleLayout;
}

createLayout的结果存储在mLayout然后绘制使用:

The result of createLayout is stored in mLayout and then drawn using:

Bitmap bitmap = Bitmap.createBitmap(128, 128, BITMAP_CONFIG);

// Set default density to avoid scaling.
bitmap.setDensity(DisplayMetrics.DENSITY_DEFAULT);

Canvas canvas = new Canvas(bitmap);
mLayout.draw(canvas);

showBitmap(bitmap);

使用上述XML,我的手机我得到这个:

With the XML above, on my handset I get this:

在平板电脑,它看起来是这样的:

On the tablet it looks like this:

另外,如果我硬code我的XML中使用的图像的精确像素值,它看起来像平板电脑的版本。箭头图像44px,中心1稍大。

Also, if I hard code my XML to use the exact pixel values of the image it looks like the tablet version. The arrow images are 44px, the center one is slightly larger.

这感觉就像我需要一种方法来设置设备的密度编程用它强制手表的密度。如何让我的布局看起来正确的手表?我想preFER一个解决方案,我能避免硬编码的像素值,因为这不是我们如何做的事情在Android上。

It feels like I need a way to set the density of the device programatically to force it to the density of the watch. How do I make the layout look correct on the watch? I would prefer a solution where I can avoid hard-coding the pixel values since it's not how we do things on Android.

推荐答案

尝试存储您可绘制在res /绘制-nodpi文件夹,应该从应用密度停止机器人。

Try storing your drawables in the res/drawable-nodpi folder, that should stop Android from applying density.

这是如在8益智游戏可用<一做href="http://developer.sonymobile.com/wp/2012/05/07/music-player-and-8-game-extensions-for-smartwatch-now-available-as-open-source/"相对=nofollow>这里。

This is e.g. done in the 8 puzzle game that is available here.

这篇关于索尼SmartWatch的XML布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆