0

I'm having an issue with my layout being displayed in portrait/landscape mode. Basically, the hierarchy of my layout goes like this: Main (Workspace view) -> TextView + Listview (w/ BaseAdapter) -> Listview Item.

My issue is, if I'm starting out in portrait mode my items display correctly as they should. But then if I rotate the device, what happens is my entire layout gets shifted over about half a screen (i.e. when I switch, about half of the left side of the View is completely black, and it thinks my true "left edge" is in the middle of the screen - I can see the items which are supposed to be aligned left in the middle). On the flip side of this, if I begin in landscape mode and switch to portrait mode, half of the right side of the screen is completely black and the "right edge" is in the middle and I can see my rightmost items ending there.

Here is the layout I'm working with... First my View within the Workspace (Listview uses a BaseAdapter):

<?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">

    <TextView android:id="@+id/tvMainChannel"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="Disconnected"
        android:textColor="#FFFFFF"
        android:singleLine="true"/>

    <ListView android:id="@android:id/list"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"/>
</LinearLayout>

And here is my individual listview items which are inflated into the above ListView (in horizontal arrangement, each item should display from left to right: Image, Text, Image):

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:orientation="horizontal">

    <ImageView android:id="@+id/images"
        android:layout_height="30dp"
        android:layout_width="wrap_content"
        android:paddingLeft="5px"
        android:paddingRight="5px"
        android:layout_alignParentLeft="true"/>

    <ImageView android:id="@+id/images_ping"
        android:layout_height="30dp"
        android:layout_width="wrap_content"
        android:paddingLeft="5px"
        android:paddingRight="5px"
        android:layout_alignParentRight="true"/>

    <TextView android:id="@+id/text"
        android:layout_height="30dp"
        android:layout_width="wrap_content"
        android:gravity="center_vertical"
        android:text="Username"
        android:textColor="#FFFFFF"
        android:layout_toRightOf="@+id/images"/>

</RelativeLayout>

I've tried switching things around between Linear and Relative, but I've gotten no where...kind of at a loss as to what might be the cause of this.

Any insight is much appreciated.

Thanks!

EDIT: For a little more clarification, this is my main.xml file which uses Workspace:

<?xml version="1.0" encoding="utf-8"?>
<com.test.MultiView xmlns:app="http://schemas.android.com/apk/res/com.test"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mvMain"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    app:default_screen="0">

    <include android:id="@+id/main_rtb" layout="@layout/main_rtb" />
    <include android:id="@+id/main_listview" layout="@layout/main_listview" />
</com.test.MultiView>
BCS
  • 215
  • 2
  • 14

1 Answers1

1

Update

The actual answer to this question was a problem with a custom top-level layout component, originally omitted from the question, and which was adapted from a thread elsewhere on stackoverflow. See comments to this answer for details.

Original answer (entirely incorrect, but not entirely useless)

Problem must be in your item layout. Suggest using a LinearLayout (the 'orientation' attribute is not valid for RelativeLayout) like this:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:orientation="horizontal">

    <ImageView android:id="@+id/images"
        android:layout_height="30dp"
        android:layout_width="wrap_content"
        android:paddingLeft="5px"
        android:paddingRight="5px"
        />


    <TextView android:id="@+id/text"
        android:layout_height="30dp"
        android:layout_width="wrap_content"
        android:layout_weight="1"
        android:gravity="center_vertical"
        android:text="Username"
        android:textColor="#FFFFFF"
        />

    <ImageView android:id="@+id/images_ping"
        android:layout_height="30dp"
        android:layout_width="wrap_content"
        android:paddingLeft="5px"
        android:paddingRight="5px"
        />

</LinearLayout>

Notice the use of android:layout_weight and the removal of RelativeLayout-specific attributes android:layout_alignParentLeft and android:layout_alignParentRight.

Reuben Scratton
  • 38,595
  • 9
  • 77
  • 86
  • Appreciate the response. This doesn't seem to be working. The TextView (@+id/tvMainChannel) and ListView (@android:id/list) are still offset on the x-axis, and begin at what appears to be the exact width of the portrait view starting from the right edge of the screen going left (i.e. starting x = right edge in landscape - portrait width). – BCS Dec 13 '10 at 19:07
  • Oh I see. What is your android:screenOrientation set to in your manifest file? – Reuben Scratton Dec 13 '10 at 19:19
  • There isn't one set in my manifest file; however, I am using android:configChanges="keyboardHidden|orientation" to override my activity from being destroyed on screen rotation – BCS Dec 13 '10 at 19:48
  • Is it possible that you have some weird / broken soft keyboard installed? What happens if you change the input method on the textview via a long-press? Sorry to be guessing so much... I suspect your problem is not in the code you posted at all. – Reuben Scratton Dec 13 '10 at 20:20
  • Also, what device is this, and what version of Android? – Reuben Scratton Dec 13 '10 at 20:21
  • The TextView isn't actually clickable, it just displays different status messages when Connected/Disconnected. I'm actually replicating this issue within the emulator, and I've been testing it on devices too and it has the same issue. If it helps any, I'm using a Workspace view which holds 2 different views (1 which is a TextView + EditText, and the other is what I described above). If the latter is shown on the screen during the orientation change, it gets screwed up, but if I'm on the former and rotate then swipe to the latter it is formatted as it should be...if that makes sense. – BCS Dec 13 '10 at 20:27
  • The emulator is running 2.1, I've tested on a 2.1 and 2.2 device. – BCS Dec 13 '10 at 20:28
  • Rewind, rewind... what is this "Workspace" view? You mean the layout you posted isn't the entire window layout? Now I re-read your question I realised I assumed your outer LinearLayout was your "workspace". What is the layout you setContentView() with? – Reuben Scratton Dec 13 '10 at 20:35
  • The Workspace view is a modified Workspace.java from Launcher2. The code I'm currently using can be found here: http://stackoverflow.com/questions/2501307/horizontal-tabish-scroll-between-views This is my main view, which everything else is falling under. Apologies if I wasn't clear in previous posts. – BCS Dec 13 '10 at 20:40
  • I edited the main post to include my main.xml file (at the bottom of the post) – BCS Dec 13 '10 at 20:48
  • Can you attach MultiView.java? I don't see it in the linked thread (I only see a WorkspaceView class in one of the answers) – Reuben Scratton Dec 13 '10 at 21:14
  • MultiView is the Workspace view, I just renamed the source file. It is the same content as that WorkspaceView in the answer you're referring to. – BCS Dec 13 '10 at 21:46
  • After much debugging and reading, I narrowed the problem down to that Workspace I was using...I didn't think that was the root cause because one of my views within it was displaying correctly, but the other wasn't which led me to believe it was a layout problem. In fact the issue is coming from the bitmap drawing methods in the Workspace, so I just removed them as well as stripped out all of the wallpaper stuff since I didn't plan on using it anyway. Your comments sort of pushed me towards the workspace view, so thank you. And the info you posted about the layout was helpful as well. :-) – BCS Dec 14 '10 at 05:03
  • Glad you got there in the end BCS! Sorry I couldn't assist with the debugging, had to get some sleep (it was getting late UK time). – Reuben Scratton Dec 14 '10 at 09:26