我真的很困惑.从developer.android.com上的文档来看,为了保持我的图像在所有当前Android设备上正确缩放(宽高比),我需要以下所有这些布局.这真的是每个人都在做什么?我错过了什么,或者我应该以不同的方式解决这个问题?
Run Code Online (Sandbox Code Playgroud)Low density Small screens QVGA 240x320 ------------------------------------------------ layout-small-ldpi layout-small-land-ldpi Low density Normal screens WVGA400 240x400 (x432) ------------------------------------------------ layout-ldpi layout-land-ldpi Medium density Normal screens HVGA 320x480 ------------------------------------------------ layout-mdpi layout-land-mdpi Medium density Large screens HVGA 320x480 ------------------------------------------------ layout-large-mdpi layout-large-land-mdpi High density Normal screens WVGA800 480x800 (x854) ------------------------------------------------ layout-hdpi layout-land-hdpi Xoom (medium density large but 1280x800 res) ------------------------------------------------ layout-xlarge layout-xlarge-land
我已经做了一些关于构建适用于多种屏幕尺寸的布局的研究,我正在寻找一些澄清.
通常的做法是为三种屏幕尺寸(小,中,大)中的每一种制作单独的布局文件,还是可以通过更简单的方法完成此操作?
我一直在大屏幕设备上测试我的项目,即使我使用DIP(密度无关像素)进行填充,边距等,当我在较小的屏幕上查看时,它仍然会重新填充.我应该为中型屏幕设计我的项目,然后让Android适当地扩展它吗?
我不确定这是不是一个好问题,但我正在寻找设计多种屏幕尺寸的常见做法.你是做什么?
编辑:除此之外,例如,假设我有一个位于屏幕底部40dip的按钮,我应该写40dip,还是应该使用像40*screenWidth/blahblah之类的像素数学这样根据用户的屏幕尺寸进行缩放?我对UI的经验有限......
背景:
这就是为什么我决定创建我自己的布局,你要告诉每个孩子他们的重量(和周围的重量)与它的大小相比应该是什么.
看来我已经成功了,但出于某种原因,我认为有一些我无法追查的错误.
其中一个错误就是textView,即使我为它提供了大量空间,它也会将文本放在顶部而不是放在中心.另一方面,imageViews工作得很好.另一个错误是,如果我在自定义布局中使用布局(例如frameLayout),则其中的视图将不会显示(但布局本身将会显示).
请帮我弄清楚它为什么会发生.
如何使用:而不是线性布局的下一个用法(我故意使用长XML,以显示我的解决方案如何缩短事物):
<LinearLayout 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:orientation="vertical">
<View android:layout_width="wrap_content" android:layout_height="0px"
android:layout_weight="1" />
<LinearLayout android:layout_width="match_parent"
android:layout_height="0px" android:layout_weight="1"
android:orientation="horizontal">
<View android:layout_width="0px" android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView android:layout_width="0px" android:layout_weight="1"
android:layout_height="match_parent" android:text="@string/hello_world"
android:background="#ffff0000" android:gravity="center"
android:textSize="20dp" android:textColor="#ff000000" />
<View android:layout_width="0px" android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
<View android:layout_width="wrap_content" android:layout_height="0px"
android:layout_weight="1" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我所做的只是(x是将视图本身放在权重列表中的位置):
<com.example.weightedlayouttest.WeightedLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.example.weightedlayouttest"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" tools:context=".MainActivity">
<TextView android:layout_width="0px" android:layout_height="0px"
app:horizontalWeights="1,1x,1" app:verticalWeights="1,1x,1"
android:text="@string/hello_world" android:background="#ffff0000"
android:gravity="center" android:textSize="20dp" android:textColor="#ff000000" />
</com.example.weightedlayouttest.WeightedLayout>
Run Code Online (Sandbox Code Playgroud)
我的特殊布局代码是:
public class WeightedLayout extends ViewGroup
{
@Override …Run Code Online (Sandbox Code Playgroud) android android-layout android-linearlayout android-layout-weight android-percent-library
我正在开发一款Android应用,我们针对所有屏幕尺寸进行定位?我如何制作布局?我应该为每种类型的屏幕制作不同的layout.xml,还是有其他"有效"的做事方式?