0

I have an android app with various buttons and text views. The buttons, textviews and edittext fields are spaced around on the screen using measurment of dp. So for example a button will have: 'margintop from left 10dp'

The problem is for high density phones. I have created a new layout for higher density screens and named them either layout-large or layout-sw600-sw720 (as the problem is with galaxy s3).

But the phone still keeps calling the normal layout file which is suited to density screen 480 x 800.

I read that the s3 calls the mormal layout file. So if I change the xml in the normal file to that of the high density, what should I do with the lowere density layout xml? what file name should I call it and will the phone call this file or the normal file again?

Extract of XML layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/duroodscreen"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="5dp" >

<Button
android:id="@+id/dmute"
android:layout_width="48dp"
android:layout_height="33dp"
android:layout_alignParentLeft="true"
android:background="@drawable/soundon" />

<Button
android:id="@+id/dreset"
style="?android:attr/buttonStyleSmall"
android:layout_width="48dp"
android:layout_height="33dp" 
android:layout_alignParentRight="true"
android:background="@drawable/customresetbutton" />

<TextView
android:id="@+id/dcount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/dmute"
android:layout_marginLeft="25dp"
android:layout_marginTop="36dp"
android:gravity="center"
android:singleLine="true"
android:text="Numbers"
android:textSize="25sp" />

Refference in Manifest:

<supports-screens 
android:resizeable="true"
android:smallScreens="true" 
android:normalScreens="true" 
android:largeScreens="true"
android:anyDensity="true" />
Mustafa
  • 755
  • 1
  • 7
  • 16

4 Answers4

1

In this case, as much of a pain it is, it would probably be better to make a layout solely for the Galaxy S3 rather than trying to rewrite everything to correct the mistake of one manufacturer.

Thus you would:

get the model of the phone

if "galaxy S3" 
   layout with "my_layout_galaxy_s3"
else -> layout with 
   layout with "my_layout"
Community
  • 1
  • 1
DeeV
  • 35,865
  • 9
  • 108
  • 95
  • I think it will affect all handsets with the same res – Mustafa Jan 12 '13 at 17:36
  • It looks as though I may need to use the above code, where do i place it? In the java class above setContentView? – Mustafa Jan 13 '13 at 00:21
  • 1
    You place it wherever you're going to use the layout. You may want a utility class that's just like `useLayout(Context ctx, int layoutId)`, and then put the check in that. – DeeV Jan 13 '13 at 15:37
  • 1
    In this *specific* case, you would probably use just it in `onCreate` via the `setContentView()` method, yes. Since that is where you're setting the main layout of the entire activity. The strategy can be used any time you're inflating views though. – DeeV Jan 13 '13 at 15:39
1

Don't confuse screen size with density. The phone has a normal sized screen. So what you see is OK. Also note, the sw600 qualifier refers to a width of 600 dp not pixels.

To provide resources for another density use a density qualifier (mdpi, hdpi, ...).

Henry
  • 42,982
  • 7
  • 68
  • 84
1

layout-normal indicates the size of the screen, not the density

you have to create layout-normal-mdpi and layout-normal-hdpi files

use layout-normal-xhdpi for galaxy s3

Ilya Blokh
  • 11,923
  • 11
  • 52
  • 84
0

Why are you using so many pixel values everywhere? Pixel values should only be used for small things like padding a few pixels between elements. The reason for that is to avoid problems like this in the first place.

For example, why are you specifying width and height of the buttons? First off, they have no text so why not use ImageButton? Secondly, just make the images the size you want and use wrap_content. Same with the text field. The idea of an android layout is really to avoid doing all the pixel calculations and instead do everything relatively, so that devices can make their own decision based on their hardware how it will look best.

If you really want to fight the system, it would probably be easier to do it all the way- use an AbsoluteLayout and specify exact pixel coordinates for everything. Otherwise embrace how Android does things or be ready for a world of pain.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127