I want to change some views when the orientation changes for example i want to put text view from bottom of the screen to screen's right side vertically when the orientation changes from portrait to landscape mode.How to achieve it?
Create two distinct layouts with the same name (i.e. mylayout.xml), and put one in res/layout-port and the other in res/layout-land. If you call
setContentView( R.layout.mylayout );
in the onCreate() method of your activity, then Android will select the correct layout depending on whether the device is in portrait or landscape orientation.
Related
How do I change the orientation of a LinearLayout when a device changes orientation? What changes would be needed in the *.xml's associated *.kt file?
For example, the device is in Portrait and displays a LinearLayout with a vertical orientation. When the device turns and becomes Landscape, the LinearLayout should have a horizontal orientation.
I imagine that two different layouts would be called depending on the configuration change but I'm not sure.
You need to use separate folders for your layouts : layout for portrait mode and layout-land for landscape mode, and put two separate xml files with the same name in each one.
One of xml files with LinearLayout with a vertical orientation and another xml file with LinearLayout with horizontal orientation.
For instance look at How to Add/Create Landscape Layout in Android Studio
Integrated MPAndroid Line charts, when screen rotates to landscape I want to only graph view to be shown in full screen and all other things should be hidden. I have restricted orientation to "Portrait", how can I trigger when screen rotates to landscape even though it is restricted.
you can duplicate the XML layout file of your activity, and put it inside folder /res/layout-land if you don't have it create it. Then you can change the visibility to "gone" at the views you don't want to show in landscape mode.
Also don't restrict the orientation to portrait for this activity
I want to make independent layout from screen orientation.
Something like this:
(source: userapi.com)
Okay so what you want has nothing to do with the landscape mode, you just want the button text such that it seems that those are in landscape mode. I can suggest something which is kind of a hack.
For that you can have the buttons as usual with more height and less width and align them with left and the right edge of the screen.
For button text you need to make a .jpg or a .png of your text, rotate it and set that as the background for the button.(if you change button text dynamically then you need other snaps of text). This wont look good but it is one of the ways to do what you looking for.
You mean, you want to have seperate layout files for portrait and landscape views ?
Then you should create two different files each in layout and layout-land directory under res.
res
|_ layout
|_ layout-land
Android will call the appropriate layout based on the device configuration.
To retain the data, you may use
#Override
public Object onRetainNonConfigurationInstance() {
Bundle bundle = new Bundle();
return bundle;
}
and get the bundle in onCreate()
final Bundle savedBundle = (Bundle)getLastNonConfigurationInstance();
Can we fix the orientation for one imageview in framelayout, and orientation of other children of frame layout be controlled by the sensor?
I want to fix the orientation of image in background and on top of that need to show some reults in textviews. If I fix the activity in landscape then I can't draw the text portrait wise.
You can use separate xml for portrait and landscape mode.
1.you have to create separate folders layout-land, layout-port
2.save the xml in it.
3.Be sure with both have the same name.
You can refer here
Orientation can only be applied on activities,we cannot set the orientation of views.
I have done my application in portrait configaration but when load my application in to device its coming portraint configaration but I keep in landscape mode missing some controls. So I want to add scroll view to screen when changing the config to landscape. How I can add ScrollView to screen ?
You could define two version of your layout.
"res/layout/your_layout.xml" - this will be used in portrait mode
"res/layout-land/your_layout.xml" - android will use this when in landscape orientation
If you don't want to do to many changes in your layout you can add ScrollView to landscape version of your_layout.xml.
Regards!