繁体   English   中英

如何正确调整布局大小? -安卓

[英]How to resize the layout properly? - Android

我正在尝试为索尼智能手表2。

我正在尝试制作一个由一个文本框,两个单选按钮和一个按钮组成的基本转换器应用程序。 然而,在手表上进行测试时,一切都是巨大的。 如果我在日食中调整大小,那么这些东西会消失,而其他事情又会如何呢? 手表上的图片: http : //content.screencast.com/users/jeremyc12/folders/Jing/media/050d6158-1daa-4ebe-8eb2-ed8a46e3d024/2014-04-23_1334.png

这是我的xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="@dimen/smart_watch_2_control_width"
android:layout_height="@dimen/smart_watch_2_control_height"
android:background="@color/myColor"
android:onClick="calculate"
tools:ignore="PxUsage" >

<EditText
    android:id="@+id/editText1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:inputType="numberSigned"
    android:width="5px" >

    <requestFocus />
</EditText>

<RadioButton
    android:id="@+id/radioButton1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/editText1"
    android:layout_alignBottom="@+id/editText1"
    android:layout_alignParentRight="true"
    android:layout_marginRight="16dp"
    android:checked="true"
    android:text="@string/kmh" />

<RadioButton
    android:id="@+id/radioButton2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/button2"
    android:layout_alignLeft="@+id/radioButton1"
    android:text="@string/miles" />

<Button
    android:id="@+id/button2"
    style="?android:attr/buttonStyleSmall"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_toRightOf="@+id/editText1"
    android:text="@string/calc" />

我在这里看到两个问题:

  1. 正如Aritra指出的那样,请确保在XML布局中没有进行任何缩放。 因此,请勿仅使用“ px”作为“ dp”。

  2. SW2仅支持Android中的少数几个视图。 有关详细信息,请参见此处: http : //developer.sonymobile.com/reference/sony-addon-sdk/com/sonyericsson/extras/liveware/aef/control/Control.Intents#EXTRA_DATA_XML_LAYOUT

    这里不包括EditText,RadioButton和Button视图,因此即使没有缩放比例,您也会看到一些奇怪的问题。

   <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ff0000"
    android:onClick="calculate" >

    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:inputType="numberSigned"
        android:width="5px" >

        <requestFocus />
    </EditText>

    <RadioButton
        android:id="@+id/radioButton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/editText1"

        android:layout_toRightOf="@+id/radioButton2"
        android:checked="true"
        android:text="kmh"
        android:textSize="8sp" />

    <RadioButton
        android:id="@+id/radioButton2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/editText1"
        android:text="miles" 
        android:textSize="8sp"/>

    <Button
        android:id="@+id/button2"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/radioButton2"
        android:layout_toRightOf="@+id/editText1"
        android:text="calculate" 
        android:textSize="8sp"/>

</RelativeLayout>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM