문제

Since my UI is quite simple I'd like to cater for both landscape and portrait in one xml file.

In portrait mode everything is as I exactly want it to be.

In landscape the main_title TextView is barely shown. Is there a work around for this?

<?xml version="1.0" encoding="utf-8"?>
<ScrollView android:background="@color/background"
    android:layout_width="fill_parent" android:padding="20dip"
    android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android">
    <LinearLayout android:layout_height="fill_parent"
        android:layout_gravity="center" android:orientation="vertical"
        android:layout_marginTop="30dip" android:id="@+id/LinearLayout01"
        android:layout_width="fill_parent">
        <TextView android:layout_marginBottom="15dip"
            android:textSize="24.5sp" android:layout_height="wrap_content"
            android:id="@+id/TextView01" android:layout_gravity="center"
            android:text="@string/main_title" android:layout_width="wrap_content"></TextView>
        <Button android:layout_marginBottom="15dip"
            android:layout_height="wrap_content" android:id="@+id/start_button"
            android:text="@string/start_label" android:layout_width="fill_parent"></Button>
        <TextView android:textSize="18sp" android:layout_height="wrap_content"
            android:id="@+id/TextView02" android:text="@string/time_window_please_select_label"
            android:layout_width="wrap_content"></TextView>
        <Spinner android:layout_height="wrap_content" android:id="@+id/spinner"
            android:prompt="@string/time_window_prompt" android:layout_width="fill_parent"></Spinner>
        <TextView android:layout_height="wrap_content"
            android:layout_marginBottom="10dip" android:id="@+id/status_label"
            android:layout_width="wrap_content"></TextView>
        <TextView android:layout_height="wrap_content"
            android:layout_marginBottom="10dip" android:id="@+id/status_time_label"
            android:layout_width="wrap_content">
        </TextView>
        <ImageView android:layout_marginTop="60dip" android:id="@+id/info_button"
            android:src="@drawable/info" android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:layout_gravity="bottom|right" />
    </LinearLayout>

</ScrollView>

Links:

http://www.doc.ic.ac.uk/~am907/landscape.png

http://www.doc.ic.ac.uk/~am907/portrait.png

도움이 되었습니까?

해결책

looks like the problem lies with your margin and padding values.

best option may be to have 2 different layouts for this, 1 being portrait and other being landscape. create another folder named layout-land and layout-port in your res folder. then copy the layout file into both of these folders and make appropriate changes for the orientation.

see the android docs for more info about providing different resources for different orientations and so on: http://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources

다른 팁

add a blank textview at the top of the file, ie above the textview which is not visible. maybe your content area is very big and the screen is not able to support it. The problem that you are facing should not be happening in the first place.... but this is a work around. Also try switching emulators...

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top