Admob - How to detect horizontal orientation and hide admob? - android

I am new to programming in Java and Android. I got admob to work at the most basic level, and whenever the device is at the landscape orientation, admob tends to popup and occupy a huge potion of the screen.
What is the best way to detect the orientation and hide the ads from displaying if it is in horizontal orientation? Is it necessary to put the admob application in a thread to check for change in orientation and hide/unhide it?
Please advice.
Thanks!

Can you just not include it in your layout XML file for landscape? You can have a landscape version of your layout by including "-land" at the end of the layout folder name. For example:
/res/
/layout/
/main.xml
/layout-land/
/main.xml
If main.xml is the layout you have loading for an activity, the OS will automatically load the one in the layout-land folder for when the phone is a landscape orientation. Therefore in that XML file you can re-adjust the admob ad in the layout or remove it completely (if it is a layout object? I've never user admob).

Related

How to set different layouts for different orientations in a fragment

I have an activity which contain 3 fragments. 2 of them have data in a listview therefore when user rotate the screen everything is ok. but on my third fragment which contain buttons, when the user rotate the screen to landscape orientation,everything goes astray!
my third fragment in protrait orientation
my third fragment in landscape!
I have even tried to use scrollview but it's not working because when in landscape i don't want that big space at the middle. i wan't 3 x 2 buttons arrangment(i have 6 buttons.) when in landscape. and i think i can only achieve that by using 2 xml layouts for my fragment.
Question is how can i do that?
Make another layout folder layout-land under res and create landscape orientation layout file under this folder
After great help from sai Phani(see his comments above). i finally achieved my objective which was to create a landscape layout for my fragment by doing the following.
Create a folder under src\main\res and call it layout-land
copy your fragment layout xml (e.g peoplefragment.xml) which is in src\main\res\layout and paste it into src\main\res\layout-land folder. Don't change the file name!
Once you have pasted it, you can change the views alignment the way you would like them t appear on landscape. for my sutuation, i wanted them to appear like this in landscape
You may design your layouts that looks good for both portrait and landscape but you may customize for both orientation.
Look at SO link on the same issue # Android: alternate layout xml for landscape mode. The idea is simply to create folder names the correct way specified in Google documentation.
A good Google webpage is # Supporting Multiple Screens, search for "Using configuration qualifiers". There is a table stating Orientation and the folder names to use.

Change a Layout to use a Imageview or 2 imageviews

I´m a little familiarized with android development, so I will do a magazine app, with some pages using imageviews, one requisite is the app will work in Landscape and Portrait mode, but with one diference, in Portrait will show one page, Landscape will show 2 pages. I always worked with others developers that did the layout, but this time I will do all work. The pages will change using swype method, so I think using a android view pager is an adequate method to do this: http://developer.android.com/training/animation/screen-slide.html but I need to change between a portrait and landscape view, how can I do this?
You can create a layout to landscape mode and other to portrait. For example you activity_main.xml layout is on folder res/layout you can create a version on res/layout-land with the same name.
for more details please read: http://developer.android.com/guide/practices/screens_support.html#qualifiers

layout display height issue on rotation mode

i create a app with some forms, they display right i want, the problem is on rotate screen, the form width it's ok but the layout height i have a issue because it don't display all items of the layout, trying to find a solution i put a scrollview for the linear layout, it works but, some of this forms have listviews inside, so the listviews scroll property has been blocked by the scrollview and finally i can't display all the layout info. I want to know if some one knows a solution for this issue and can help me.
follow below steps.
1) create a folder in res directory as res/layout-land.
2) suppose you have main.xml layout in res/layout folder.
3)Create one layout name main.xml into res/layout-land folder, name this layout as main.xml. design you UI as you want to show to the user in Landscape mode.
Now when you run your app and change Orientation . system automatically called main.xml according to the Orientation, SUppose phone is in Landscape mode, then it will show main.xml of layout-land folder
see this example

Button self "rearranging"

Wondering how I do build a layout with self rearranging button, when the user turns his device from portrait to landscape, using relativelayout ?
I do not want to use scrolling on my layout and I have a lot of buttons
You can provide two different main.xml (or any layout xml file) Place one in res/layout/ and one in res/layout-land/ When the device switches orientation the system will handle the "magic" of switching to the appropriate file.
Here is some documentation about supporting these type of behaviors...
If I'm understanding your question correctly what you are looking to do is have one layout displayed for portrait mode and another for landscape mode. This is actually fairly easy to accomplish.
Here is a link to a quick tutorial:
How to change your layout in Android landscape / portrait mode

How to add an XML File to Current Activity Window in Android

Hi guys in my android application i have used Tabs through out the application.When iam in the Portrait orientation i need to display the Tabs.Whenever iam in the Landscape orientation i need to put a layer just above the TabBar so that the TabBar will be in the background.Here in the Landscape orientation the background TabBar runs ,that is just we have added one layer on top of the TabBar.And also i need to display different layout in the landscape orientation.I have heared about the Window object of the Current Activity that we can add a XML layout to the Window and makes it visible and invisible whenever we require.But i haven't find any code regarding Window.Any Suggestions
You can define different layouts for each orientation. For portrait layouts use the layout-port folder, for landscape use layout-land. Android will choose the right one depending on the orientation of the device.
See http://developer.android.com/guide/topics/resources/providing-resources.html

Categories

Resources