Having an issue with layout cutoff/offset in my view
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:androi开发者_开发问答d="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>
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
.
精彩评论