如何创建为320dp和360dp布局? [英] How can I create layout for both 320dp and 360dp?

查看:282
本文介绍了如何创建为320dp和360dp布局?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很失望。我刚刚完成我的项目的基础上360dp的标准屏幕,但是当我试图在摩托罗拉Atrix运行我有一个惊喜。摩托罗拉Atrix是360dp而不是320dp,因为他的宽度为540px。现在,我打破我的头,找出这个问题得到解决。如何创建一个布局360dp?

I'm very disappointed. I just finished my project based on 360dp for "normal screens", but when I tried to run in Motorola Atrix I had a surprise. Motorola Atrix is 360dp instead 320dp, because his width is 540px. Now I'm breaking my head to find out that problem to be resolved. How can I create a layout for 360dp?

我尝试了所有这些:

  • RES /值-sw360dp
  • RES /布局sw360dp

main.xml中

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

    <Button
        android:background="#AAAA11"
        android:id="@+id/button1"
        android:layout_width="@dimen/default_width"
        android:layout_height="@dimen/default_height"
        android:text="SOME TEXT 1"         
        />


    <Button
        android:background="#FFAA11"
        android:id="@+id/button2"
        android:layout_width="@dimen/default_width"
        android:layout_height="@dimen/default_height"
        android:text="SOME TEXT 2"
        android:layout_alignParentRight="true" />
</RelativeLayout>

RES /价值/ strings.xml中

res/values/strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <dimen name="default_width">160dp</dimen>
    <dimen name="default_height">160dp</dimen>

</resources>

摩托罗拉Atrix

Motorola Atrix

三星Galaxy SII

Samsung Galaxy SII

推荐答案

在设计布局一般来说,当你想避免规划为特定的像素尺寸。如果你想分开所有布局的基础上像你这样的像素,那么你就必须几乎为每一个设备的一种布局(有这么多的设备在世界不同大小的屏幕)。通常你会希望提供版面资源的几个不同类别的大小。 布局小布局正常布局大 ,等等。如果你提供这些和你的布局是建立在一个很好的方式,应该扩展到不同大小的设备pretty的好。

Generally when designing your layout you want to avoid planning for a specific pixel size. If you were to separate all of your layouts based on pixels like you want to, then you'd have to almost provide one layout for every single device (There are so many devices with different sized screens in the world). Usually you'll want to provide layout resources for a few different categories of size. layout-small, layout-normal, layout-large, etc. If you provide those and your layouts are built in a good manner it should scale to the different sized devices pretty well.

有什么具体的,当你在较大尺寸的设备上运行它就是错了你的布局?或许,如果你张贴的,我可以帮你试图解决它,而无需通过像素大小来分隔布局。

Is there something specific that is wrong with your layout when you run it in the larger sized device? Perhaps if you post that I can help you to try to solve it without needing to separate your layouts by pixel size.

支持多画面的在开发者文档中有许多关于如何伟大的信息构建应用程序,使他们很好地扩展。

Supporting Multiple Screens in the developer docs has lots of great information about how to build your applications so that they will scale well.

编辑:

解决你的问题不是为宽度使用一个静态的DP值,而不是让这些按钮将增长到紧线,以填满屏幕的宽度但是很多空间(水平)的一个潜在方法。你可以做到这一点与layout_weight并设置宽度 FILL_PARENT 。我没有机会,现在偏食,所以我无法测试,但我想肯定也有办法,你可以得到没有的LinearLayout这个效果,但是这是我想到的第一种方式。

One potential way to solve your problem is not use a static dp value for the width, instead allow the buttons to grow to takeup however much space (horizontally) in order to fill up the width of the screen. You can do that with layout_weight and setting the width to fill_parent. I don't have access to eclipse now so I can't test, but I think surely there is also a way you could get this effect without the linearlayout, but this was the first way that I thought of.

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

    android:background="#DFEFF1">

    <LinearLayout
     android:id="@+id/buttonRow"
     android:orientation="horizontal"
     android:layout_height="@dimen/default_height"
     android:layout_width="fill_parent">


    <Button
        android:background="#AAAA11"
        android:id="@+id/button1"
        android:layout_width="0"
        android:layout_height="@dimen/default_height"
        android:text="SOME TEXT 1"         
        android:layout_weight="1"
        />


    <Button
        android:background="#FFAA11"
        android:id="@+id/button2"
        android:layout_width="0"
        android:layout_height="@dimen/default_height"
        android:text="SOME TEXT 2"
        android:layout_weight="1" />

</LinearLayout>
</RelativeLayout>

这篇关于如何创建为320dp和360dp布局?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆