- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在开发一个 Android 2.2.2 应用程序,它将支持多种屏幕尺寸并且所有屏幕都是纵向的。我不会支持横向。
我已经在 HTC Desire 和三星 Galaxy Tab 7.7 上测试了以下布局。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/no_conectado"
android:orientation="vertical" >
<TextView
android:id="@+id/labelSelGateName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:layout_marginTop="80dp" />
<TextView
android:id="@+id/labelSelOpened"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" />
<ProgressBar
android:id="@+id/indicatorActivityView"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginTop="22dp"
android:layout_gravity="center_horizontal" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="110dp"
android:layout_marginTop="60dp"
android:orientation="horizontal" >
<ImageButton
android:id="@+id/btnMyGates"
android:layout_width="50dp"
android:layout_height="110dp"
android:layout_marginLeft="20dp"
android:layout_weight=".33"
android:background="@null"
android:contentDescription="@string/layout_empty"
android:onClick="onGateClick" />
<LinearLayout
android:layout_width="90dp"
android:layout_height="110dp"
android:layout_weight=".33"
android:orientation="vertical" >
<ImageButton
android:id="@+id/btnOpen"
android:layout_width="90dp"
android:layout_height="55dp"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@null"
android:contentDescription="@string/layout_empty"
android:onClick="onOpenDoorClick" />
<ImageButton
android:id="@+id/btnClose"
android:layout_width="90dp"
android:layout_height="50dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@null"
android:contentDescription="@string/layout_empty"
android:onClick="onCloseDoorClick" />
</LinearLayout>
<ImageButton
android:id="@+id/btnOptions"
android:layout_width="50dp"
android:layout_height="110dp"
android:layout_marginRight="20dp"
android:layout_weight=".33"
android:background="@null"
android:contentDescription="@string/layout_empty"
android:onClick="onOptionClick" />
</LinearLayout>
<ImageButton
android:id="@+id/btnFaqs"
android:layout_width="110dp"
android:layout_height="60dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:background="@null"
android:contentDescription="@string/layout_empty"
android:onClick="onFAQClick" />
<ImageButton
android:id="@+id/btnInfo"
android:layout_width="110dp"
android:layout_height="60dp"
android:layout_gravity="right"
android:layout_marginTop="20dp"
android:background="@null"
android:contentDescription="@string/layout_empty"
android:onClick="onInfoClick" />
</LinearLayout>
我有 ldpi、mdpi、hdpi 和 x-hdpi 的图像。
背景图片看起来不错,但是所有小部件(TextView
、ProgressBar
、ImageButton
等)都没有在正确的位置,当我在 Samsung Galaxy Tab 上进行测试。
我使用“Nexus One”作为模型在 Eclipse 上设计了这个布局。
Here人们建议我对每个屏幕尺寸和密度只使用一种布局,但它不起作用。我使用的是 dp
单位和 fill_parent
等,但它在 Galaxy Tab 上有所不同。
我是否需要针对 x-large
屏幕尺寸的布局?
最佳答案
确实,您收到的建议很好:可能只有一个布局文件,但正如评论中已经建议的那样,硬编码尺寸并不好 , 即使你使用 dp
或 dip
,特别是当您针对所有可用的屏幕尺寸和密度时。
相反,您应该将这些值替换为维度值的链接。
例如,而不是 android:layout_marginLeft="10dp"
, 你会有类似的东西
android:layout_marginLeft="@dimen/textview_margin_left"
其中textview_margin_left定义在dimens.xml中,在不同的文件夹中有不同的值;
可能在文件夹 values 中:<dimen name="textview_margin_left">10dp</dimen>
,
在文件夹 values-large 中:<dimen name="textview_margin_left">20dp</dimen>
,
而在 values-xlarge 中:<dimen name="textview_margin_left">30dp</dimen>
但这只是一个示例,您必须在所有尺寸和分辨率上进行测试,并为您的布局找到最佳值。在 Eclipse 中,在 Graphical Layout
中模式下,您可以轻松了解您的布局在各种设备上的外观,只需单击 Nexus One,然后从列表中选择另一个型号,布局就会自动更新。
此外,您可以入住dimens.xml
所有文本大小,这对于超大型设备非常有用。
仅使用一个 RelativeLayout
取而代之的是许多叠瓦状的 LinearLayouts
也可能是一个好主意,并为您的对象使用相对定位,而不是一些硬编码值。
关于android - 相同的布局在 Samsung Galaxy Tab 上看起来不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11626248/
我正在尝试执行 vagrant up 但一直遇到此错误: ==> default: IOError: [Errno 13] Permission denied: '/usr/local/lib/pyt
我在容器 div 中有一系列动态创建的不同高度的 div。 Varying text... Varying text... Varying text... Varying text.
通过 cygwin 运行 vagrant up 时遇到以下错误。 stderr: /bin/bash: /home/vagrant/.ansible/tmp/ansible-tmp-14872260
今天要向小伙伴们介绍的是一个能够快速地把数据制作成可视化、交互页面的 Python 框架:Streamlit,分分钟让你的数据动起来! 犹记得我在做机器学习和数据分析方面的毕设时,
我是 vagrant 的新手,正在尝试将第二个磁盘添加到我正在用 vagrant 制作的虚拟机中。 我想出了如何在第一次启动虚拟机时连接磁盘,但是当我关闭机器时 然后再次备份(使用 'vagrant
我是一名优秀的程序员,十分优秀!