scaling in Android
I have been recently trying to write a layout for android app. At first I debugged it with a real handset and the layout looked ok. However later I tried running it on emulator but on different resolution. Then it doesn't fit in the screen. Width looks fine, but the height not. My handset resolution is 480x800. Could it have anything to do with aspect ratio. I have all my dimensions in dp. Some of the emulator's resolutions look fine, others however don't. Shouldn't Android scale it by it self?
Heres the look at the layout file:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<RelativeLayout
android:id="@+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="0px"
android:layout_height="0px"
android:focusable="true"
android:focusableInTouchMode="true"/>
<EditText
android:id="@+id/SetAddr"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/StartServer">
</EditText>
<LinearLayout
android:orientation="horizontal"
android:id="@+id/LinearLayout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/SetAddr"
android:gravity="center_horizontal">
<Button
android:id="@+id/PingStart"
android:layout_width="@dimen/StartButtonWidth"
android:layout_height="@dimen/StartButtonHeight"
android:layout_below="@id/SetAddr"
android:text="@string/Start"
/>
<Button
android:id="@+id/PingStop"
android:layout_width="@dimen/StopButtonWidth"
android:layout_height="@dimen/StopButtonHeight"
android:layout_below="@id/SetAddr"
android:layout_toRightOf="@id/PingStart"
android:text="@string/Stop"
/>
</LinearLayout>
<TextView
android:id="@+id/PingResults"
android:layout_width="@dimen/ResultsViewWidth"
android:layout_height="@dimen/ResultsViewHeight"
android:layout_below="@id/LinearLayout2"
android:textColor="#000"
android:background="#FFF"
android:layout_centerHorizontal="true"
android:scrollbars="vertical"
/>
<LinearLayout
android:orientation="horizontal"
android:id="@+id/LinearLayout3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/PingResults"
android:gravity="center_horizontal">
<Button
android:id="@+id/PingStartTrace"
android:layout_width="@dimen/OptionButtonWidth"
android:layout_height="@dimen/OptionButtonHeight"
android:text="@string/Trace" >
</Button>
<Button
android:id="@+id/PingStartLookup"
android:layout_width="@dimen/OptionButtonWidth"
android:layout_height="@dimen/OptionButtonHeight"
android:layout_toRightOf="@id/PingStartTrace"
android:text="@string/Lookup" >
</Button>
<Button
android:id="@+id/PingStartWebget"
android:layout_width="@dimen/OptionButtonWidth"
android:layout_height="@dimen/OptionButtonHeight"
android:layout_toRightOf="@id/PingStartLookup"
android:text="@string/WebGet" >
</Button>
<Button
android:id="@+id/PingStartOptions"
android:layout_width="@dimen/OptionButtonWidth"
android:layout_height="@dimen/OptionButtonHeight"
android:layout_toRightOf="@id/PingStartWebget"
android:text="@string/Options" >
</Button>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
Dimens file:
<resources>
<dimen name="StartButtonHeight">50dp</dimen>
<dimen name="StartButtonWidth">250dp</dimen>
<dimen name="StopButtonHeight">50dp</dimen>
<dimen name="StopButtonWidth">60dp</dimen>
<dimen name="ResultsViewWidth">290dp</dimen>
<dimen name="ResultsViewHeight">330dp</dimen>
<dimen name="OptionButtonHeight">50dp</dimen>
<dimen name="OptionButtonWidth">75dp</dimen>
</resources>
On some resolutions I see only 开发者_开发技巧half textview and no buttons below it.
精彩评论