简体   繁体   English

适用于正常屏幕尺寸的Android版式设计

[英]Android Layout Design for normal screen sizes

I am a hobbiest app developer and I feel I have a good grasp on android basics but the main thing that I struggle at is app design. 我是最喜欢的应用程序开发人员,我觉得我对android基本知识有很好的了解,但是我最主要的工作是应用程序设计。 I understand how to develop for different screen sizes and densities. 我了解如何针对不同的屏幕尺寸和密度进行开发。 But the main thing I struggle at is each of the normal and other sizes cover such a range of sizes within their respective categories. 但是,我要努力解决的主要问题是每个正常尺寸和其他尺寸在其各自类别中都覆盖了如此范围的尺寸。 I have been searching and searching and not been bale to find a solution. 我一直在搜索,而不是一直在寻找解决方案。

The main issue I am having is when designing using eclipse, i make a design using nexus one at the design looks perfect for what I want when I swap to a smaller screen like 3.2 HVGA or even the nexus galaxy which are all normal sized images, the location of my images have moved. 我遇到的主要问题是使用eclipse进行设计时,我使用nexus进行设计,该设计看起来非常适合我换成较小尺寸的屏幕(例如3.2 HVGA或什至是常规尺寸图像的nexus星系)时想要的东西,我图像的位置已移动。 So what looked perfect for the nexus one looks awful on some other normal screen sizes. 因此,在其他正常屏幕尺寸下,看起来最完美的链接看起来很糟糕。

What can be done to ensure if an image is directly next to another that it stays that way on a different screens. 可以采取什么措施来确保图像是否紧挨着另一个图像,使它在其他屏幕上保持原样。 I will give an example of the current design I am working on and I hope somebody can explain what im doing wrong/how i can improve. 我将举例说明当前正在设计的产品,希望有人能解释我做错了什么/我如何改进。

Nexus One Design: Nexus One设计:

在此处输入图片说明

3.2 HVGA: 3.2 HVGA:

在此处输入图片说明

  the xml generated:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/RelativeLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:columnCount="4"
    android:orientation="vertical" >

    <Button
        android:id="@+id/Button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:background="@drawable/i1"
        android:text="Button" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:background="@drawable/i2" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/Button1"
        android:layout_alignTop="@+id/Button1"
        android:layout_marginLeft="106dp"
        android:layout_marginTop="160dp"
        android:background="@drawable/i3" />

    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/button2"
        android:layout_alignBottom="@+id/button2"
        android:layout_alignRight="@+id/Button1"
        android:layout_marginRight="112dp"
        android:background="@drawable/i4" />

    <Button
        android:id="@+id/button4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/button3"
        android:layout_alignLeft="@+id/button3"
        android:background="@drawable/i5" />

</RelativeLayout>

You need to create different images for each of the screen resolutions and put them into the respective drawable folder drawable--hdpi , drawable-mdpi , drawable-xhdpi , etc. Also be sure that you are using dp in your xml file, which it appears you are. 您需要为每种屏幕分辨率创建不同的图像,并将它们放入相应的drawable文件夹drawable--hdpi drawable-xhdpidrawable-mdpidrawable-xhdpi等。此外,请确保在xml文件中使用dp ,看来你是。 Just be sure you always do so. 只要确保您始终这样做即可。

Designing for the different screens can be tricky because you have to essentially create the same image 4 or 5 times. 为不同的屏幕进行设计可能很棘手,因为您必须将相同的图像创建4到5次。

Also, make sure you are testing on actual handsets, because the emulator doesn't always give you an accurate layout. 另外,请确保您正在实际的手机上进行测试,因为仿真器并不总是能为您提供准确的布局。

Try adding another layout for side buttons to group them together, and then center that layout: 尝试为侧按钮添加另一个布局以将它们分组在一起,然后将其居中:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/RelativeLayout1"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:columnCount="4"
                android:orientation="vertical"
                android:layout_alignParentTop="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true">

    <Button
        android:id="@+id/Button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:background="@drawable/i1"
        android:text="Button" />

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                    android:id="@+id/RelativeLayout2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true">

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="false"
            android:layout_alignParentTop="true"
            android:background="@drawable/i2"
            android:layout_alignParentLeft="true"/>

        <Button
            android:id="@+id/button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/i3"
            android:layout_below="@+id/button1"
            android:layout_alignParentLeft="true"/>

        <Button
            android:id="@+id/button3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/i4"
            android:layout_below="@+id/button4"
            android:layout_toRightOf="@+id/button2"/>

        <Button
            android:id="@+id/button4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/i5"
            android:layout_toRightOf="@+id/button2"
            android:layout_alignParentTop="true"/>
    </RelativeLayout>
</RelativeLayout>

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

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