即使具有相同的分辨率和倾斜度,屏幕在不同设备上的显示也不同

发布于 2024-12-05 00:21:08 字数 5116 浏览 6 评论 0原文

好吧,伙计们。问题:我有一个布局,需要视图出现在背景图像内置的“框”内。所以..精确的布局是必须的。我完成了布局,它在模拟器和 Samsung Galaxy S 上看起来很棒,但当我把它放在 Droid X 上时,视图会向上移动。问题是这两款手机都被认为是具有 HDPI 的中型屏幕。我显然不能使用不同的布局文件夹来修复它。我在清单中将“anyDensity”设置为 false。尝试了 minSDK 3 技巧。我的资源是从drawable-hdpi 文件夹中提取的,但应该不会产生影响。我唯一能想象到的原因是我给出的特定保证金值(即使是在 DIP 中)。但我不知道如何在没有这个的情况下实现在特定位置具有视图的布局。有什么帮助吗?公共软件你在哪里?谢谢你们。

编辑: 我越想越发现自己的想法是错误的。 (自从我编写 Android 布局代码以来已经有一段时间了)DIP 正在做它应该做的事情。我放置的每个屏幕上的尺寸完全相同,但我想要完成的是让视图随着屏幕尺寸而扩展。因此,如果屏幕较大,边距和间距会随着屏幕而增大。本质上,我的整个布局需要一个 fill_parent ,但我不能将其用于精确布局。有什么想法吗?

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

    <TextView
        android:layout_height="wrap_content"
        android:layout_width="150dp"
        android:layout_marginTop="20dip"
        android:layout_marginRight="10dip"
        android:layout_gravity="right"
        android:gravity="center_horizontal"
        android:text="Text Here"
        android:textSize="15dip"
        android:textColor="#253B85" />

    <TextView
        android:id="@+id/code"
        android:layout_height="wrap_content"
        android:layout_width="150dp"
        android:layout_marginTop="10dip"
        android:layout_marginRight="10dip"
        android:layout_gravity="right"
        android:gravity="center_horizontal"
        android:text="5D6"
        android:textSize="9dip"
        android:textColor="#000000" />

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <ImageView
            android:id="@+id/icon"
            android:layout_width="90dip"
            android:layout_height="90dip"
            android:layout_marginLeft="20dip"
            android:layout_marginTop="10dip"/>

        <TextView
            android:id="@+id/name"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:layout_marginTop="19dip"
            android:layout_marginRight="20dip"
            android:layout_toRightOf="@id/icon"
            android:layout_alignParentRight="true"
            android:gravity="right"
            android:text="Really Long Name"
            android:textSize="17dip"
            android:textColor="#253B85" />

        <TextView
            android:id="@+id/importantInfo"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:layout_marginTop="5dip"
            android:layout_marginRight="20dip"
            android:layout_below="@id/name"
            android:layout_alignParentRight="true"
            android:gravity="right"
            android:text="50% off"
            android:textSize="30dip"
            android:textStyle="bold"
            android:textColor="#253B85" />

        <TextView
            android:id="@+id/dateLabel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dip"
            android:layout_marginTop="22dip"
            android:layout_below="@id/icon"
            android:text="date: "
            android:textColor="#253B85" />

        <TextView
            android:id="@+id/dateText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="22dip"
            android:layout_below="@id/icon"
            android:layout_toRightOf="@id/dateLabel"
            android:text=" "
            android:textColor="#253B85" />

        <TextView
            android:id="@+id/moreInfo"
            android:layout_width="fill_parent"
            android:layout_height="33dip"
            android:layout_marginLeft="22dip"
            android:layout_marginTop="3dip"
            android:layout_marginRight="24dip"
            android:layout_below="@id/dateLabel"
            android:gravity="center"
            android:maxLines="2"
            android:textSize="10dip"
            android:text=" "
            android:textColor="#253B85" />

        <ImageView
            android:id="@+id/qrIcon"
            android:layout_width="fill_parent"
            android:layout_height="106dip"
            android:layout_marginLeft="22dip"
            android:layout_marginTop="11dip"
            android:layout_marginRight="24dip"
            android:layout_below="@id/moreInfo" />

    </RelativeLayout>

    <Button
        android:id="@+id/submitButton"
        android:layout_width="160dip"
        android:layout_height="40dip"
        android:layout_marginTop="14dip"
        android:layout_gravity="center_horizontal"
        android:onClick="buttonRedeemOnClickListener"
        android:background="@drawable/button_background"
        android:text="Redeemed Coupon"
        android:textColor="#FFFFFF" />

</LinearLayout>

Okay guys. Problem: I have a layout that needs views to appear inside of the "boxes" that are built into the background image. So..precise layout is a must. I got the layout up and it looked great on the emulator and the Samsung Galaxy S, but when I throw it on the Droid X the views are shifted up. The problem is that both phones are considered Medium Screens with HDPI. I obviously can't use different layout folders to fix it. I have "anyDensity" set to false in the manifest. Tried the minSDK 3 trick. My resources are pulling from the drawable-hdpi folder, but shouldn't make a difference. The only thing I can imagine would be causing this is the specific margin values I'm giving (even in DIP). But I have no idea how to achieve a layout with views in specific locations without this. Any help please?? Commonsware where are you on this one. Thanks guys.

Edit:
The more I think about it, the more I realize I was wrong in my thinking. (it has been a while since I coded Android layout) DIP is doing exactly what it should be. The sizes are exactly the same on every screen I put them on, but what I'm wanting to accomplish is to have the view expand with the screen size. So if the screen is larger the margins and spacing grow with the screen. Essentially I need a fill_parent for my entire layout, but I can't use that with precise layout. Any ideas?

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

    <TextView
        android:layout_height="wrap_content"
        android:layout_width="150dp"
        android:layout_marginTop="20dip"
        android:layout_marginRight="10dip"
        android:layout_gravity="right"
        android:gravity="center_horizontal"
        android:text="Text Here"
        android:textSize="15dip"
        android:textColor="#253B85" />

    <TextView
        android:id="@+id/code"
        android:layout_height="wrap_content"
        android:layout_width="150dp"
        android:layout_marginTop="10dip"
        android:layout_marginRight="10dip"
        android:layout_gravity="right"
        android:gravity="center_horizontal"
        android:text="5D6"
        android:textSize="9dip"
        android:textColor="#000000" />

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <ImageView
            android:id="@+id/icon"
            android:layout_width="90dip"
            android:layout_height="90dip"
            android:layout_marginLeft="20dip"
            android:layout_marginTop="10dip"/>

        <TextView
            android:id="@+id/name"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:layout_marginTop="19dip"
            android:layout_marginRight="20dip"
            android:layout_toRightOf="@id/icon"
            android:layout_alignParentRight="true"
            android:gravity="right"
            android:text="Really Long Name"
            android:textSize="17dip"
            android:textColor="#253B85" />

        <TextView
            android:id="@+id/importantInfo"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:layout_marginTop="5dip"
            android:layout_marginRight="20dip"
            android:layout_below="@id/name"
            android:layout_alignParentRight="true"
            android:gravity="right"
            android:text="50% off"
            android:textSize="30dip"
            android:textStyle="bold"
            android:textColor="#253B85" />

        <TextView
            android:id="@+id/dateLabel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dip"
            android:layout_marginTop="22dip"
            android:layout_below="@id/icon"
            android:text="date: "
            android:textColor="#253B85" />

        <TextView
            android:id="@+id/dateText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="22dip"
            android:layout_below="@id/icon"
            android:layout_toRightOf="@id/dateLabel"
            android:text=" "
            android:textColor="#253B85" />

        <TextView
            android:id="@+id/moreInfo"
            android:layout_width="fill_parent"
            android:layout_height="33dip"
            android:layout_marginLeft="22dip"
            android:layout_marginTop="3dip"
            android:layout_marginRight="24dip"
            android:layout_below="@id/dateLabel"
            android:gravity="center"
            android:maxLines="2"
            android:textSize="10dip"
            android:text=" "
            android:textColor="#253B85" />

        <ImageView
            android:id="@+id/qrIcon"
            android:layout_width="fill_parent"
            android:layout_height="106dip"
            android:layout_marginLeft="22dip"
            android:layout_marginTop="11dip"
            android:layout_marginRight="24dip"
            android:layout_below="@id/moreInfo" />

    </RelativeLayout>

    <Button
        android:id="@+id/submitButton"
        android:layout_width="160dip"
        android:layout_height="40dip"
        android:layout_marginTop="14dip"
        android:layout_gravity="center_horizontal"
        android:onClick="buttonRedeemOnClickListener"
        android:background="@drawable/button_background"
        android:text="Redeemed Coupon"
        android:textColor="#FFFFFF" />

</LinearLayout>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

停滞 2024-12-12 00:21:08

添加到清单文件:::

<supports-screens android:smallScreens="true" android:resizeable="true" android:normalScreens="true" android:largeScreens="true" android:anyDensity="true"></supports-screens>

Add in manifest file:::

<supports-screens android:smallScreens="true" android:resizeable="true" android:normalScreens="true" android:largeScreens="true" android:anyDensity="true"></supports-screens>
独孤求败 2024-12-12 00:21:08

根据您目前的代码,我认为您没有尝试过为不同的尺寸编写不同的布局。这很耗时,具体取决于您要编码的尺寸数量,但非常值得这样做。我能看到的唯一问题是,您是否要为每个屏幕分辨率进行布局,这是不值得的。

Based on your code currently, I don't think you have tried coding different layouts for different sizes. It's time consuming depending on how many sizes you are going to code for, but well worth the trouble of doing so. The only issue I can see is if you are going to make a layout for every screen resolution, which is not worth the trouble.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文