【问题标题】:Different display of SmartWatch control screenSmartWatch控制屏幕的不同显示
【发布时间】:2013-01-08 16:26:59
【问题描述】:

我的应用以 3x3 的简单网格呈现数字 1-9 的简单屏幕。您可以在此处查看我的 SmartWatch 上的外观:https://www.youtube.com/watch?v=ijh5EOTTR-w

现在,这一切都正确。问题是用户报告他的设备上同一个应用程序的显示非常不同,可以在这里看到:https://docs.google.com/open?id=0BwywSxPvL53dcmlwd0RJQWhVa0E

两个智能手表都在相同的版本上运行:

  • 智能手表版本 0.1.A.3.7
  • 主机应用程序 1.2.37

唯一的区别是手机型号:问题出现在 Sony Xperia S 上,而在 Sony Xperia Sola 上一切正常。这两款手机都运行索尼的 Android Gingerbread(在升级到 ICS 后,Sola 上的所有手机都可以正常工作)。

我尝试以不同的方式指定数字(文本)的大小,使用 dip、px、mm,但在所有情况下,在 Sola 上它们的尺寸都比在 Xperia S 上小得多。

我不知道是什么造成了这种显着差异,希望能提供任何提示或帮助。谢谢!

附:我没有使用任何可绘制对象。

这是我的代码,让事情变得更加清晰:

1) 保存值的网格:

<?xml version="1.0" encoding="utf-8"?>
<!-- px is used since this is a layout for the accessory display. -->
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="@dimen/smart_watch_control_height"
    android:layout_height="@dimen/smart_watch_control_width" 
    xmlns:tools="http://schemas.android.com/tools" 
    tools:ignore="PxUsage">

<GridView
    android:id="@+id/grid"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginRight="0px"
    android:layout_marginTop="-13px"
    android:columnWidth="40px"
    android:gravity="center"
    android:horizontalSpacing="0dip"
    android:numColumns="3"
    android:padding="0dip"
    android:stretchMode="none"
    android:verticalSpacing="0dip" />

</RelativeLayout>

2) 将以下元素之一放入网格的每个单元格:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/text1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textSize="16dip"
    android:textStyle="bold"
    android:textColor="#0000FF"
    android:gravity="center"
    android:padding="0dip"
/>

3) 控件中的绘制逻辑:

// Create background bitmap for animation.
background = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
// Set default density to avoid scaling.
background.setDensity(DisplayMetrics.DENSITY_DEFAULT);

LinearLayout root = new LinearLayout(mContext);
root.setLayoutParams(new LayoutParams(width, height));

LinearLayout sampleLayout= (LinearLayout) LinearLayout.inflate(mContext,
        R.layout.speed_dial_control, root);

// draw on the sampleLayout
GridView gridView = (GridView) sampleLayout.findViewById(R.id.grid);
gridView.setAdapter(adapter);

// adjust the size
sampleLayout.measure(width, height);
sampleLayout.layout(0, 0, sampleLayout.getMeasuredWidth(),
    sampleLayout.getMeasuredHeight());

// Draw on canvas
Canvas canvas = new Canvas(background);
sampleLayout.draw(canvas);

// Send bitmap to accessory
showBitmap(background);

【问题讨论】:

    标签: sony sony-smartwatch


    【解决方案1】:

    所以,另一个答案,因为第一个答案仍然是相关的 - 对于可绘制对象。

    首先,您要使用 PX,因为 SmartWatch 显示屏由 128x128 像素组成。不应应用密度。

    我已经稍微修改了你的 xmls。大多数情况下,我已经删除了不必要的定义。

    网格:

    <?xml version="1.0" encoding="utf-8"?>
    <!-- px is used since this is a layout for the accessory display. -->
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="@dimen/smart_watch_control_height"
        android:layout_height="@dimen/smart_watch_control_width"
        tools:ignore="PxUsage" >
    
        <GridView
            android:id="@+id/grid"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:numColumns="3" />
    
    </RelativeLayout>
    

    如您所见,我遗漏了您的大部分原始 xml。你真的只需要定义网格和列数。其余的将自行处理 - 即网格将均匀分布在父布局 (128x128) 中。

    细胞:

    <?xml version="1.0" encoding="utf-8"?>
    <TextView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@android:id/text1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:gravity="center"
        android:textColor="#0000FF"
        android:textSize="26px"
        android:textStyle="bold"
        tools:ignore="PxUsage" />
    

    这里我将 textSize 更改为像素,并删除了填充,因为您不需要声明它。

    这应该可以为您解决问题。我在不同的手机型号上进行了测试 - 效果很好。如果没有,您的适配器可能是问题所在。为了测试,我使用了一个简单的 ArrayAdapter,如下所示:

    String[] numbers = new String[] {
            "1", "2", "3", "4", "5",
            "6", "7", "8", "9"
    };
    
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(mContext, R.layout.cell, numbers);
    

    干杯!

    【讨论】:

    • 混蛋,非常感谢!这个版本很好用!设置边距是为了使整个布局居中。
    【解决方案2】:

    要阻止 Android 应用密度,请尝试使用 res/drawable-nodpi 文件夹。

    我认为您的问题可能类似于this question

    【讨论】:

    • 不,我没有使用任何drawables,只是xml布局文件。
    • 好的!您是否以与完成方式相同的方式构建图像(带有文本),例如在 SDK 的 SampleControlExtension 中? IE。通过使用布局、位图和画布?如果没有,请检查一下,可能会更适合您。
    • 我遵循代码示例,但我不使用任何位图。我发布了上面的代码。感谢您的回答,我希望代码能让事情变得非常明显并找到解决方案。
    • 带有 dip 的文本大小不正确,但您说您尝试了替代方案。我认为 px 是正确的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-11
    • 1970-01-01
    • 1970-01-01
    • 2012-04-27
    • 2014-08-27
    相关资源
    最近更新 更多