In the manifest file of this application, I have specified the screen orientation to be landscape for each activity. However, in each layout file it lists android:orientation="vertical" as default. The application sometimes crashes, sometimes it doesn't, could these values be conflicting?
No way, it is different things at all.
Landscape for activity mean how to show activity for user
android:orientation="vertical" for LinearLayout mean how LinearLayout will draw its children views
android:orientation in layout defines how the child view will be stacked on the screen (for example see LinearLayout). The orientation in the manifest is all about the screen orientation (or the orientation of specific Activity).
Related
I have a FrameLayout inside my fragment, and three other layouts inside my FrameLayout. I want one of the three layouts to change its view positions on a landscape, so I created two XML files for this layout and put them inside layout-port and layout-land accordingly, but the layout is still using the portrait layout in landscape mode. So what else do I need to do?
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
.
.>
<include
layout="#layout/xxx"
... />
<include
layout="#layout/xxx2"
... />
...
</FrameLayout>
I want to change the layout of xxx on a landscape, and I created 2 XML for xxx.
The default folder for layout is layout no need to add port suffix to it, when you create a landscape version you should make sure that its in the folder layout-land and the device will automatically select this layout version at runtime. for more information on supporting different screen sizes look at this documentation
I have a Fragment which uses different layouts in landscape and portrait orientation. In landscape mode, the root element is a LinearLayout, while in portrait mode it is a ScrollLayout:
res/layout/fragment.xml
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".NewBathingSiteFragment"
tools:showIn="#layout/activity_new_bathing_site"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/nbs_scrollView">
....
res/layout-land/fragment.xml
<LinearLayout
android:orientation="horizontal"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".NewBathingSiteFragment"
tools:showIn="#layout/activity_new_bathing_site"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="#+id/nbs_linearLayout">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/nbs_scrollView">
...
I'm getting this error on orientation change:
java.lang.IllegalArgumentException: Wrong state class, expecting View State but
received class android.widget.ScrollView$SavedState instead. This usually
happens when two views of different type have the same id in the same hierarchy.
This view's id is id/newBathingSiteFragment. Make sure other views do not use
the same id.
No two views have the same ID in the same layout (they do have the same ID in the two different layouts, because I need to find them using findViewById()). The ID newBathingSiteFragment is the ID for the Fragment, and is set in XML in the activity layout.
I was able to make the problem go away by adding a LinearLayout as the root element for portrait mode as well, making the structure identical to landscape mode (except that in landscape mode there is one more view in the LinearLayout displaying next to the ScrollView).
Is this the preferred solution to this? Or is there a better way, without adding an "unnecessary" LinearLayout to portrait mode?
I have an activity that per our requirements has to be locked into landscape orientation. However when the user holds the device in portrait we display a view on top of it. Up until now it has just been an image so I have rotated the image and I display it. Really the image is also being displayed in landscape but since I have rotated it, it appears like it is in portrait.
Now I need to complicate this by having a more complex view with layouts being displayed (layouts, textviews, buttons, etc) instead of just an image. The same "rotation" doesn't seem to work because stuff is displayed off of the screen. What is the recommended solution to show one view in portrait while the view behind it is locked in landscape?
edit:
if the idea is to literally have the view underneath to show rotated 90% while the top view is in "normal" view, you could possibly call setRotation method, available since API 11
view.setRotation(90);
edit: below is my old answer, please see above my updated question
Do not lock the view in landscape. Instead use the layout/ and layout-land/ folders to place appropriate views. For example:
layout/main.xml
<FrameLayout
android:layout_width=”match_parent”
android:layout_height=”match_parent”>
<include layout="#layout/main_content"/>
</FrameLayout>
layout-land/main.xml
<FrameLayout
android:layout_width=”match_parent”
android:layout_height=”match_parent”>
<include layout="#layout/main_content"/>
<FrameLayout
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:padding="144dp"
background="#4000">
<include layout="#layout/top_content"/>
</FrameLayout>
</FrameLayout>
what's the best layout to use to display a series of image button, side by side (as displayed in attached image), and that will fills the screen horizontally when the orientation changes to horizontal (as attached)?
horizontal orientation http://img254.imageshack.us/img254/657/layoutxs.png
vertical orientation http://img208.imageshack.us/img208/2428/layouthy.png
<GridView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:numColumns="auto_fit" >
</GridView>
It looks like you want to use something like FlowLayout, which doesn't exist in Android. You can make your own, however. More information
How can I do something like a FlowLayout in Android?
http://nishantvnair.wordpress.com/2010/09/28/flowlayout-in-android/
I have an activity with a layout similar to yours, but I use a different method. What I do is define a different xml layout for landscape and portrait. So I have layout-port/mylayout.xml and layout-land/mylayout.xml and the system determines which one the activity should use.
just create two separate layout files and call setContentView() in your onOrientationChanged().
I want to know how to change the orientation of my layout.
In manifest I have:
android:screenOrientation="landscape"
In layout.xml I have
android:orientation="horizontal"
but when I click the "layout" button it still appears as a vertical layout.
Thank You.
There is a dropdown within the layout editor that allows you to select landscape or portrait orientation.