0

我的应用程序以 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 上小得多。

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

PS我没有使用任何drawables。

这是我的代码,可以使事情更加清晰:

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);
4

2 回答 2

2

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

首先,您要使用 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);

干杯!

于 2012-10-23T08:38:57.170 回答
0

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

我认为您的问题可能与此问题相似。

于 2012-10-17T11:23:04.517 回答