Screen appearing differently on different devices even with dip and same resolution
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:开发者_JS百科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>
Add in manifest file:::
<supports-screens android:smallScreens="true" android:resizeable="true" android:normalScreens="true" android:largeScreens="true" android:anyDensity="true"></supports-screens>
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.
精彩评论