I'm using the showcaseview library in my Android app to display a first time tutorial to new users. So far it's been fairly straightforward to get going; I have a number of different viewpager tabs at the top of the page that are getting consecutively showcased, which is great ... in portrait mode.
However when the device is rotated, or I start my app in landscape orientation, the title and content text that I have for my showcase is displayed at the bottom of the screen and it eventually overflows off the screen. The showcase text content isn't more than a sentence and I can't think I'm the first person to have this problem so I'm wondering if any one else has come across this and how they solved it?
I was thinking that since showcaseview calculates the best position for the text based on free canvas space that I could probably move my content up by reducing the radius of the showcase cirlce, although I have yet to try this.
Also, I don't want to restrict users by locking the orientation to portrait mode during the tutorial.
EDIT: I've temporarily settled for locking the screen to portrait orientation if I deem the height and width of the target device to be too small. It's not my ideal solution so I'm still keen to hear the thoughts of any showcaseview users out there.
Related
Is there any way I can achieve the desired behaviour on rotation of the device, as illustrated in the following sketch (the wavy thing is a widget). Most likely this is something that would be controlled by the launcher, rather than controlled programmatically from any one app -- if so, is there any launcher that allows this?
Basically the reason I'm asking is because I want the widget to behave as illustrated (the widget is what I'm coding), even when the user's device is set to rotate the home screen on device rotation. Basically the only way I can see this working is if the grid layout is fixed relative to the physical screen, with the app icons just rotating within their box, and the widgets either updating their content for the new layout, or just keeping the previous content (so that the content rotates with the screen).
For updating of widget content, is there any way of detecting screen home screen rotation programmatically (different to screen rotation, since the home screen may not rotate)? This is relevant to me even for the "what I get" scenario, because the aspect ratio of the widget seems to change when the home screen is rotated, and I need to detect this and update the widget content to fit better.
dfdd
Use:
1. layout-sw480dp
2. layout-sw600dp
3. layout-sw720dp
You are unlikely to find a solution for this as the home screen (launcher) varies wildly in implementation. Many launchers don't support landscape orientation, and expecting the launcher to accommodate a widget which can expand in two different directions is simply asking too much of them.
For the launchers which do support landscape orientation, the widget should be repositioned for free without effort on your part. You may wish to detect which orientation the widget is in (such as via getResources().getConfiguration().orientation) when your provider is choosing a layout, setting up views etc, but that's about it.
I'm in the beginning stages of developing my first app and wanted to know what I can do from now to make sure my app runs equally well across all Android devices. I don't have access to another device right now to test whether or not it will scale but have I noticed that if I rotate my device to landscape, the items in the view (e.g. buttons, icons) don't scale at all to fit the screen. This makes me worry that it won't be very compatible with other devices.
I find myself putting items in each view by messing with paddings and margins in the XML till I have it right - but now I realise that this makes the layouts specific to my device. Is there a "correct" way of doin this? For instance, if I had to draw 4 horizontal lines equally spaced across the width of a screen how would I achieve this so that the width between the lines are determined according to the size of the screen?
I have a large image in my MainActivity but for some reason it gets really small if I switch to landscape.
Can anybody shed some light on this? Would be really grateful, thanks.
This issue is addressed here:
http://developer.android.com/guide/practices/screens_support.html
My application is bitmap intensive, with pixel-exact layout (it's a sort of game, actually, and it's pretty hard to avoid this pixel-based coordinates).
What I wanted to do is to perform some layout calculations and bitmap pre-scaling in my onCrete - I use well known API - getWindowManager().getDefaultDisplay().getSize() - to retrieve the screen size and do my calculations.
However, I've just hit an unexpected problem. My activity is configured as landscape only, but if I start my application on emulator and onCreate() is called while the emulator is locked, the screen size returned by getSize() indicates portrait orientation. Once I unlock the screen, onCreate() is called again, this time correctly in line with expected landscape mode dimensions.
I'm not sure how to handle this situation. I see the following options:
for each onCreate() call perform full layout calculation and resource scaling again. This is the logically correct solution, but I don't want to the same work twice, just to throw away the first result.
if onCreate() is called for portrait mode, just do nothing, and set black background (I can see there's a silly rotate animation when I unlock the screen, so this would become pretty much a fade-in animation)
Actually I'd prefer second option, but I'm slightly afraid of any side-effects. Anyone faced this problem?
Update (2012-07-08):
I've probably assigned a slightly misleading title to this question (sorry!), as the problem is not in retrieving the dimensions itself, nor calculating the layout. It's more about the activity being first created in portrait mode, and then recreated in landscape mode again, despite being declared as landscape-only. I initially expected (reasonably, huh?) the activity to be created in landscape orientation only.
I eventually decided to fill the activity with black color when it's created in portrait mode, no side effects observed. On Android 4.0 I can see actual rotation animation when I unlock the screen - a bit strange, but well, I guess it is supposed to inform the user that she should rotate the phone. Given that in portrait mode I just fill the screen with black color, this animation looks sort of like a fade-in and rotation combined - perfectly acceptable.
Use that
DisplayMetrics dm=new DisplayMetrics();
this.getWindowManager().getDefaultDisplay().getMetrics(dm);
Using this(Look code at down) only gives you screen size and if your views has static size they will be seen in different size on every different screen.
Display screen=getWindowManager().getDefaultDisplay().getSize();
How to use:
every screen has diffrent density. So use:
float density=dm.density;
with this density, you can set your views size like that:
(YOUR_ITEM_SIZE)*density;
also look here for additional information:
http://developer.android.com/reference/android/util/DisplayMetrics.html
if the emulator is locked , can't you assume that the user can't run anything anyway , so the app doesn't need to handle this end case ?
anyway , as bmavus wrote , use getMetrics for getting the screen size . also , if you need to change the screen orientation of the app , you can do so either in the manifest or in code.
for games , i would advice using opengl solutions , and if you don't have much time digging for it , you can use third party engines that can help you , such as andengine and libgdx.
I want to programmatically set a wallpaper to be an exact fit of the current screen.
Android fits the image to scroll as you change windows by defalt and so you never see the whole image on any one screen.
Applications like Wallpaper Wizardrii perform the function of setting the image to a single screen for the user, but I have never seen an answer on any forum that suggests how this is done.
Can any Android guru out there help - this problem has been doing my head in for nearly a week now!
You need to write a Live Wallpaper so you can render your image to the screen exactly how you want. If you just set a static image, the launcher app (or anything else showing the wallpaper) will be free to adjust it and resize and scroll. By writing a live wallpaper, you get to receive the requests from launcher about what it wants to happen to the wallpaper, and follow or ignore them as you want.
Also conceptually "make the wallpaper an exact fit for the current screen" is not even possible, because there is only one wallpaper, but two orientations (landscape and portrait) it can be shown in. That one wallpaper just fundamentally can't exactly fit both orientations.
We are writing an application for the T-Mobile MyTouch which is an Android based mobile phone. We have images that will be displayed on the default screen portrait mode (320 x 480).
Anticipating that the Android OS will be appearing on Netbooks with default landscape 16 : 9 screen format, what is the best way to handle images that are in a portrait mode format? In other words since you can't rotate the screen on these Netbooks, if you display a portrait mode image on landscape mode screen there will be large blank rectangles on either side of the image.
In terms of image resources within the application, such as is the case with background images, it is a common practice to have different image set for landscape and portrait mode, or even different screen sizes. Surely, you will adapt your layout to it, or at least have a good relative layout.
However, if you are wondering what to do when an image of an unknown size has to be drawn on the screen (e.g. in case of photo album application), it is fine to leave those black rectangles on both sides. Take a look at the behaviour of video player view on the Android Dev Phone 1. It will adapt the video frame height to landscape mode, and it will play the video in the landscape mode whether or not a portrait mode is more suitable.
You deal with it the same way you would deal with the user turning their phone sideways. This is as much a presentation decision as a UI one.
Remember Android supports using alternative layouts for identical Views. If you have a portrait layout e.g. res/layout/gallery.xml, you can create a landscape equivalent in res/layout-land/gallery.xml and Android will automatically load the latter layout file if the Activity is launched in landscape mode.
With the separate layout XML file, you can then arrange your image as you feel best fits the intent of your application (an application displaying medical images may well have different presentation priorities than one displaying a family portrait). You could for example just fill the background with a gradient, or more information that is otherwise hidden in portrait mode. It all depends on what you wish to achieve with your application and the lengths you are willing to go to to account for all possibilities.
But ultimately, provided the user can see the image in it's entirity without needing to flip their netbook on it's side, I imagine they'll be happy :)
You should design your screen with certain anchor points and then position the rest of the views in relation to those anchor points. For example if you have a screen layout which has a banner, a list of items and some buttons under the list then 2 of the ways these can be positioned on the screen:
Place banner at the top. Put the
list under it and then the buttons
under the list.
Place banner at
the top. Place the buttons at the
bottom of the screen and then the
list takes the space between the
banner and the buttons.
Layout 1) will have trouble with different screen sizes and the layout will look odd or may not appear correctly at all. Whereas, 2) gives you a better appearance for most screen sizes.