screen rotation in android - android

I want to use screen rotation in android device.
But I don't want to rotate whole activity.
How is this possible to rotate only some of views in a activity
Like there are two button and one ImageView.
I want to rotate only ImageView on screen orientation change.
Plz suggest the way.
Thanks.

Create another xml file with same name and put it in new folder inside res/ folder. Name that new folder layout-land. and change in your xml file according to your requirements. It will automatically change the layout file when the orientation will be changed.

Related

How can I change Android app background image when phone is tilted?

I´ve made an app where´s just some text and a background image.
When I tilt my phone my background image gets streched out..
What I want to do is when I tilt the phone I get now background image.
What you need to do is create different layouts for your views in landscape and portrait mode and put the landscape ones in res/layout-land and the portrait ones in res/layout-port. Simply get your current XML file and copy it into both the portrait and landscape stalks and then just change the drawable that is referenced for the background. That way you can have one that fits well for portrait and another that you've edited to fit for landscape views.
you need to provide a different layout for that orientation.
create a layout-landscape folder, and in that layout change the background to the one you want for your landscape layout. besides you can completely customize your landscape orientation that way.
yes you can change the background
for that you have to create another xml file with same name of the xml you are using right now
then copy all the code from your previous xml to this new xml
you have to create this xml inside the land named folder,if that folder dosent exist than crete a folder name land inside your layout folder..
you just have to change one thing in your xml and here you gooo
android:background="#drawable/yournewbackgroundname"
do not change any thing in our old xml

Android Views and Screen Orientation

Is it possible to have two Views in Android; one of which is the "background" and wont rotate when the device is rotated. And have the other one on top (the "UI-elements") rotate on orientation change?
I know I can disable/enable orientation changes for a whole activity but how would I go about that for separate Views in one activity?
I'm not sure if that's possible, but usually to support "landscape" and "portrait" orientations, you would create another folder in your "res" folder and call it "layout-land" then copy your .xml file in "layout" to "layout-land" and make the appropriate changes to your UI-elements.
If you want to keep the background the same, then I suppose you can leave it unchanged or you might have to rotate the image and save a copy of the rotated image to use in landscape orientation.
Hope that's helpful!

Select layout xml files most appropriate, depending on screen size

I would like to know if You Could select a layaout xml Differently Depending on the size of the phone screen.
I try to be more clear, I make more layout xml file, and I would like my app handles this statement
setContentView (R.layout.main)
first verifying on that size of the display is performed, and Therefore You Set the most appropriate layout xml
What you could actually do is the following:
Create a new folder for each desired configuration and name that folder with qualifiers.
If you want your application to have a different main.xml layout for different screen sizes you should make the following folders in your project.
/res/layout-small
/res/layout-normal
/res/layout-large
/res/layout-xlarge
In each of those folders have your different main.xml file layout (or whatever resource you want). Android will pick the one it matches with the device is running your application.
You can even add different resources for different configurations for drawables and even for language.
More info: http://developer.android.com/guide/topics/resources/providing-resources.html
Have you looked at this page yet?
You can query the size of the device screen, and then select which xml layout you want to use for that size screen...

Optimizing app background for orientation change?

I have a simple gradient background for my app.
So is there a way to set it so when the orientation is changed from Vertical to Landscape, the background changes to a bigger version of picture (a seperate picture, but same gradient effect)?
say you are using this image as a background in the main.xml layout file. what you have to do is create a new folder in 'res' directory named 'layout-land'
create another background image for the landscape mode.
copy the main.xml to layout-land directory.
set the landscape image as the background for the main.xml in layout-land directory.
now you have two different main.xml files. Android OS will automatically pickup the correct layout according to the orientation.
please note that widgets in patriot main.xml file should exist in landscape main.xml too with the same ID. otherwise you will get nullpointer.
You should have to create the another directory as Asanka have said in answer and do it. That solve your issue.
For more information see this.
Enjoy. :)

Center image view on rotate

I have an image view with an image and it looks find when the phone is portrait. When I turn it landscape, it rotates, however, the image isn't centered anymore. How do I go about doing that?
Create a layout-land directory in your res folder. And copy your layout files with landscape orientation. That should do it.
Rather than making a new folder and xml file and all that, I simply did
android:layout_width="match_parent"
on my image view and when I rotate the device, the image stays centered.

Categories

Resources