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.
Related
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
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!
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. :)
I want to load image runtime in my activity but it is load in portait view only.
If I want to load it in landscape it doesn't.
I also do it by both seprate xml for landscape and portrait.
and also try by only one xml.
I draw image like this
result_img.setImageDrawable(getResources().getDrawable(R.drawable.invalid_title));
But it draw in only portait layout.
goto Manifest file and remove android:screenOrientation="potrait" attribute because it affect your app to view only in potrait mode only.if you have remove it you can show in both view. and one more thing is that you havent change any xml file
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.