Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/186.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 外观的意义是什么?_Android_Xml - Fatal编程技术网

Android 外观的意义是什么?

Android 外观的意义是什么?,android,xml,Android,Xml,我想制作一个xml文件,其中的文本在所有设备上看起来至少有点相似,因为我知道我可以使用sp或textAppearance,并让它根据屏幕重新缩放 所以我试了一下,在eclipse上它的显示是这样的: 在平板电脑仿真器上: 至少从我所看到的情况来看,虽然屏幕变大了,但屏幕的大小根本没有改变,为什么?我该怎么做才能让它在所有设备上看起来都很相似,我不知道textview缩放是如何工作的 以下是我的xml: <RelativeLayout xmlns:android="http://sche

我想制作一个xml文件,其中的文本在所有设备上看起来至少有点相似,因为我知道我可以使用sp或textAppearance,并让它根据屏幕重新缩放

所以我试了一下,在eclipse上它的显示是这样的:


在平板电脑仿真器上:


至少从我所看到的情况来看,虽然屏幕变大了,但屏幕的大小根本没有改变,为什么?我该怎么做才能让它在所有设备上看起来都很相似,我不知道textview缩放是如何工作的

以下是我的xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="top"
tools:context="${relativePackage}.${activityClass}" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="30dp"
    android:text="Large Text"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/textView1"
    android:layout_below="@+id/textView1"
    android:layout_marginTop="22dp"
    android:text="Medium Text"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<TextView
    android:id="@+id/textView3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/textView2"
    android:layout_centerHorizontal="true"
    android:text="Small Text"
    android:textAppearance="?android:attr/textAppearanceSmall" />

编辑:

关于SP的相同故事:



它的大小相同,在不同的屏幕上

最好是在styles.xml中定义自己的样式。在我看来,这比仅仅依赖默认主题要好。它们确实会随着制造商的不同而变化。你的想法只有在使用Android操作系统的设备上才是正确的


而且它们的大小也不一样。如果您查看
sdk\platforms\android-4.3\data\res\values\
中的
styles.xml
,您将能够看到这一点。

但是如果我定义自己的样式,它仍然无关紧要,我将使用SP来定义它,而且SP在每个设备上看起来都不一样。

SP的大小永远不会相同。这就是好处。它将根据密度放大或缩小。e、 g.在所有设备上,15sp文本和11sp文本之间的百分比差异是相同的。@AmitK.Saha,
sp
通常与
dp
相同,除非用户在系统范围内选择较大或较小的字体。@323go,它们肯定是相同的。如果用户从设备设置更改字体比例,则可以看到差异。请说明移动仿真器和平板电脑仿真器的密度值。您会混淆大小和分辨率。灵活的UI必须基于大小。如果我有一个分辨率为480x360的5英寸屏幕,我希望一个“大”文本显示与1280x800的5英寸屏幕相同。如果它没有按比例缩放,那么高分辨率屏幕上的文本将太小而无法阅读,按钮太小而无法点击,等等。如果您制作的是160dp,则无论屏幕大小和分辨率如何,它的大小始终为1英寸。您可以自由为不同的屏幕大小创建不同的样式和布局。@AmitK.Saha我如何获得它?@323go我理解,但这意味着我需要为不同的设备创建许多不同的样式?它在哪里结束?另外,我如何区分不同的设备,如何知道使用什么以及何时使用?我想你不明白。如果我在大屏幕上使用你的应用程序,我想查看更多信息。我不想看到相同的信息,只想看到更大的信息。这会让你的UI使用起来很尴尬,如果不是很痛苦的话。如果这看起来工作量太大,您总是可以在运行时计算相对大小。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true"
android:gravity="top"
tools:context="${relativePackage}.${activityClass}" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="82dp"
    android:text="100sp"
    android:textSize="100sp" />

<TextView
    android:id="@+id/TextView01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/textView1"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="67dp"
    android:text="15SP"
    android:textSize="15sp" />