I want to use precise layout on Nexus One, my code is like this:
<?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">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="90dp">
<ImageView
android:layout_width="5dp"
android:layout_height="fill_parent"
android:src="@drawable/d10" />
<ImageView
android:layout_width="94dp"
android:layout_height="fill_parent"
android:src="@drawable/d5" />
<ImageView
android:layout_width="94dp"
android:layout_height="fill_parent"
android:src="@drawable/d6" />
<ImageView
android:layout_width="94dp"
android:layout_height="fill_parent"
android:src="@drawable/d7" />
<ImageView
android:layout_width="94dp"
android:layout_height="fill_parent"
android:src="@drawable/d8" />
<ImageView
android:layout_width="94dp"
android:layout_height="fill_parent"
android:src="@drawable/d9" />
<ImageView
android:layout_width="5dp"
android:layout_height="fill_parent"
android:src="@drawable/d10" />
</LinearLayout>
</LinearLayout>
But it turns out on Nexus One, the screen width is not 480 px. So this LinearLayout will exceed the screen width.
How should I fix this?
Several things
1) It’s not recommended to use px when designing android GUI
check available resources or this question to learn the differences between px, dp and sp.
2) If you are using drawables, which I presume are images, use
instead of trying to adjust the container (ImageView) to the content (the image). Android will take care of the rest. Learning when to use wrap_content or fill_parent is key to GUI design.
3) Nexus One IS 480 px wide. The problem lays in your layout design, just keep on working and you’ll learn the tricks that make UI design much easier in Android than most of other platforms.
Also, I asume this code snippet is contained in a View, you’ve not declared the namespace. Maybe you have something wrong in the rest of the layout.
I hope this helps.