Changing view background image on orientation change - android

If I got a graphic design for lets say a TextEdit control as a background image, is it possible to stretch the image when changing from portrait to landscape view?
I'm coming from WEB and with CSS where I could divide the background picture to 3 parts and make the background stretch dynamically. Is something like this possible in android environment or should I use different layouts for each orientation?

You can declare different graphics by dropping them in separate sub-folders of the /res directory in your project. By naming convention, your application will pick them up automatically.
For example, if you use a background image called textBackground.png and you have two versions of it depending on orientation. The app will use res/drawable/textbackground.png by default and res/drawable-land/textBackground.png when in landscape mode, for example.
Check out this doc for the full story:
http://developer.android.com/guide/topics/resources/providing-resources.html

Related

how to maintain the Image Position and Size for all size of Devices in android?

I have layout like below image and I have designed using image view and image button for this images. while run for other devices its alignment and size is Varies:
so Which layout want to use
Size based on design or device based or
any technique is there for the responsive design
**i'm using only on Landscape mode
There is a few ways to do this.
The easiest way is to use androids grid layout and build it that way,
this takes a bit of getting used to but it works well.
the 2nd way is to make alot of values folders and ajusting dimens in them:
https://developer.android.com/guide/practices/screens_support.html

How does my Xamarin.Android app know which size layout to use?

After reading through Android's guide on supporting multiple screen sizes I now know that I need to create multiple layouts for each screen size in order to make sure the elements are located where I want them.
One thing the guide didn't mention is how to programmatically specify in my Activities which layout will get loaded. Is this because Android will automatically detect which layout to use based on the name of the folder it's located in? For example, a layout in a folder named "layout-sw700dp" will be selected for devices with that screen width?
In-short, I want to know if utilizing alternate layouts for different screen sizes is simply a matter of placing the different layouts in the appropriately named and located folders. Here's a picture of the layout in Xamarin Studio with the properties pane displayed. It looks the way I want it on Nexus 4; everything centered. But when I switch to a different-sized device, the elements are no longer centered. See here.
As cricket_007 sad, you should use diferent xmls when using diferent orientations or making your app more tablet friendly.
When it comes to phone you should practise creating one xml that will cover large range of phones.
And dont use padding for placing elements on screan. For example, dont use pading to set TextView on right side of screan. If you use it lite that and set paddingLeft=250dp on some scren your textView will be placed on right edge but on tablet it will be around center.
Proper way is to set something about this:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:padding="10dp"/>
an this must be in RelativeLayout to be affective. This textView will be positioned on every phone and tablet on the right side of screen with small padding.

android app development compatible to multiple screen sizes

consider a requirement of an app which need to be run on different screen sizes. lets say app has text fields ediboxes list view etc... and in each screen size the width/height of each ui component has to vary. how to desing an UI for this kind of requirement. please suggest.
Use Width and Height as fill_Parent or wrap_content..
if you are using images make different sizes images and put it in drawable-hdpi,drawable-ldpi,xhdpi,xxhdpi.The Sizes for those imagaes are in developer.android.com
In the res folder,there exists folder named layout,that the default folder which the system find the layout defination.But people also can make other folder like
layout-480x800
layout-1024x768
and so on ,and put the layout files in it.
When the app run on a device which have the certain size,the app will auto find the layout defination in the same folder,if cant it will use the default defination.

How to Resize screen of Android

I am developing an application for whole android devices. But resolation of screens are different and that is the biggest problem how it looks. So, I want to make resizing controls and also I used absolutelayout but It is still same.. I give value to controls as dp ..
How can I solve this problem ?
You don't resize the screen of an android device - you make your app instead work with the various screen sizes.
The relevant docs are here.
You cannot hardcode the dimensions of your layout and expect it to work on every screen size. And there is no method which automatically does it unless you write it.
You might want to change your approach, use Relative Layout or Linear Layout instead and use values like fill_parent and wrap_content while designing your layout.
Another approach Android developers follow is use different resource files for different screen sizes and Android loads them automatically at runtime.
Refer to this for more info on how to work with different screen sizes effectively.

Appwidget with square layout not showing properly in landscape mode

I have built an appwidget with an square layout, and so it doesn't fit exactly in the standard widget sizes as recommended in http://developer.android.com/guide/practices/ui_guidelines/widget_design.html#sizes.
I chose a 3x2 size (android:minWidth="220dip" android:minHeight="146dip") as it is the smalllest that covers the widget's layout.
In http://developer.android.com/guide/practices/ui_guidelines/widget_design.html#design Google recommends:
"All widgets must fit within the bounding box of one of the six supported widget sizes, or better yet, within a pair of portrait and landscape orientation sizes, so your widget looks good when the user switches screen orientations"
My widget looks good in portrait mode. When switched to landscape mode (in the emulator) the layout is clipped. I tried inverting the minWidth and minHeight values in the provider's XML and then it looked perfect in landscape mode but clipped in portrait mode. Setting the size to 3x3 solves the problem, but then the widgets takes a lot of unnecessary space.
I know I can define different layouts in res/layout and res/layout-land, but in this case the layouts are not different at all, in both modes I want the widget to look square.
What I would need is something like 'xml' and 'xml-land', AFAIK this is not supported in Android.
Ideas?
What I would need is something like 'xml' and 'xml-land', AFAIK this is not supported in Android.
It is supported. All resource set qualifiers (e.g., -land) are supported for all resource types.
Whether it will help you is another matter entirely, as I am not aware that you can change actual app widget size on the fly this way.
Setting the size to 3x3 solves the problem, but then the widgets takes a lot of unnecessary space.
You are the one who is trying to force a particular pixel size (or, at least, aspect ratio). This will be fragile, as you are discovering. Furthermore, app widget cells are not guaranteed to be the same size on all devices and home screen implementations.
Hence, you are either going to need to choose an app widget size that gives you tons of extra space (your 3x3 scenario), or design a fluid app widget layout that adapts to the actual size that you are given (and therefore will not be square). Personally, I recommend the latter.

Categories

Resources