I'm making a little music app.
I`m trying to make my layout as flexible as possible, for this example this means i want to scale up the albumart and leave the rest (buttons for control, title,..) unscaled.
1) is this "good practice"? may i leave the other controls umscaled?
2) how to do this? Which atributes? i have uploaded a sample screenshot here of the design http://www.flickr.com/photos/59647462#N08/7038458497/
for your info this is highlevel overview of my xml:
<linearlayout>
/// Title
</linearlayout
<framelayout>
/// albumart | resize me block
</framelayout>
<relativelayout>
/// subfooter
</relativelayout>
<linearlayout>
/// footer
</linearlayout>
</linearlayout>
extra question: how to stick the footer to bottem of page? is this possible without relative layout?
thank you in advance, hope it's clear what i'm trying to do.
I dont know why you dont want to use relative layout... but if you use a relative layout.. I think it will be easy...Here is an example with three fields..
You can use LinearLayout. Use the layout_weight & weightSum values for stretching. Example Here -
http://developer.android.com/resources/tutorials/views/hello-linearlayout.html
http://developer.android.com/guide/topics/ui/layout-objects.html#linearlayout
1) is this "good practice"? may i leave the other controls umscaled?
I think that this depends on how you prefer your app to look on different devices. Personally I would rather use weights to scale proportionatly. (e.g. top and bottom taking up 25% each and the center section could be 50%). This would avoid controls becoming too small when moving from one resolution to the next.
2) how to do this? Which atributes? i have uploaded a sample screenshot here of the design http://www.flickr.com/photos/59647462#N08/7038458497/
I agree with Shaiful. Linear layout would provide a good layout for your design.
1) Yes, your controls should not scale but they must handle screen configurations changes and different screen densities.
2)The most useful attributes to manage that are:
android:layout_width
android:layout_height
with some
android:padding
android:layout_margin
To make it look good
Generally make sure your UI handles:
Screen size changes. For instance they change if you go from portrait mode to landscape mode.
Screen densities. Phones have different screen resolutions so make sure your images and controls scale properly (use dp instead of px).
Related
I want to be my Player Activity in the way that main things show user(such as play button ,rewind,forward ,cover ,date) and other things show when user scroll activity in all device with each inch size.I do that in way that I get screen height of device in pixel and give to relative layout programmatically and other things put below of this relative layout.Is that true?
if you ask about how to support different screen size it is devices
you should not add any layout_width or layout_height fixed size
and use weights in linear layout
Use best practices in dimensions use “dp” and in text size use “sp”.
Use nested layouts for better control and to make your activity xml less complex
You can make two designs one for big screens and one for small ones.
it is for layout , I hope it will help you .
I am wondering how I would design a calculator with graphics similar to the following: Design help for Calculator App or https://play.google.com/store/apps/details?id=jp.Appsys.PanecalST.
The key requirements:
The buttons must be squared (it can pop out etc. but squares are more aesthetically pleasing than rectangles).
It must be device compatible and retain square buttons upon orientation change
My problem is that Relative formatting (as I attempted) disorients the layout in different devices and is not as nice as I hoped. (i.e. trying to design the button to harbor no empty space in one device using relative instructions. One idea I fancy is putting a center button and orienting the others above left etc. so at the very least, no empty space is in the center.
Below is the designs I made:
I prefer the first image but I neglected 0 (only buttons for 1-9). How would attempt at transforming these designs to code?
*I think I may use ImageButtons. I will include images based on density but how would I account for different screen sizes?
First of all, for your calculator, use LinearLayout.
Link: Documentation will be found here
Secondly, To Support multiple screen,
This documentation will help, documentation1, documentation2
What would I do in this situation?
First of all, I would use the LinearLayout as my primary layout and give it an orientation > Vertical instead of RelativeLayout. This LinearLayout is for the whole screen (The output, the numbers and other functions). Then for each line, say for the output screen, I would put it in another LinearLayout (Orientation Horizontal) inside the previous LinearLayout (NestedLayout). For numbers in each row, I would use a new LinearLayout.
For the second problem of yours, I would use buttons instead of images as images take large space in perspective of buttons which will unnecessary increase the app size. To support my button for multiple screen, I would use Weight option in android for buttons. This stackoverflow answer has a nice description.
I hope it helps.
Cheers mate!
I try to implement a good reusable color picker for my Sketcher application. Instructions and screenshots are here: http://bit.ly/sketcherapp
The problem is I'm stuck with a good "resizable" UI which enable me to support wide range of devices with different screen sizes.
The top two widgets should be the same height and have proportional widths: 80 to 20. Also it would be nice to specify paddings in XML.
Current implementation is not good. I hardcoded some values into code and also it looks bad on Xoom devices because of inaccurate layout measurements.
Is there any way to implement this behavior? Ideally, I need some way to do it like with HTML tables (pseudocode):
table.width=100%, td1.width=80%, td2.padding=5px, ...
or something like that.
Current implementation:
code:
https://github.com/wargoth/Sketcher/tree/master/src/org/sketcher/colorpicker
layout:
https://github.com/wargoth/Sketcher/blob/master/res/layout/color_picker.xml
Thank you.
The top two widgets should be the same height and have proportional widths: 80 to 20.
Use a horizontal LinearLayout, android:layout_width="0dip" for both widgets, and android:layout_weight="80" and android:layout_weight="20", respectively.
Also it would be nice to specify paddings in XML.
Use android:paddingLeft and kin.
OK. I stopped boring with it and created dedicated layouts for each screen size.
I'm working on an android app that we're targeting for all screen sizes? How do i go about making my layouts? Shall i make a different layout.xml for each type of screen or is there any other "efficient" way of doing things?
Read Supporting Multiple Screens, specially the section "Best practices for Screen Independence".
Basic rules:
Use wrap_content, fill_parent, or the dp unit (instead of px), when specifying dimensions in an XML layout file
Do not use AbsoluteLayout
Do not use hard coded pixel values in your code
Use density and/or resolution specific resources
In practice, even if your layout will work on tablets, you will also want to provide different layouts for those extra large devices to enhance user experience.
Edit concerning your screenshots.
<ImageButton
android:id="#+id/btnSubmit"
android:src="#drawable/submit"
android:layout_height="22dp"
android:layout_width="85dp"
android:layout_marginTop="15dp"
android:layout_below="#+id/confirmpassword"
android:layout_centerInParent="true" />
You specify here two vertical constraints that might not play well together. Instead of layout_centerInParent, try layout_centerHorizontal.
You could also give a gravity="top|center_horizontal" to your RelativeLayout. So by default the elements get centered in the view horizontally and get sticked to the top.
Also try to align firstname below btnSignin instead of username. You might be lucky.
RelativeLayout is the most complicated layout to use. If you can't get it right after some time, you could simply decide to fall back on using combinations of nested LinearLayout
For landscape and portrait mode, you can use different xmls, incase u need to display your screen according to the orientations. I have been using this method for my apps.
As for support of multiple screen, you can go with relative layout as parent node. Dont go with absolute layout.
you have to take relative layout for any dynamic screen & all measurement will be in percent(%) or u can use the property(fill parent or wrap content), by do so u can somewhat manage layout for different screen
What is the best layout to use to support the app on different devices (Size of screen)?
EDIT
I am not just talking about resizing the layout, obviously the OS does that automatically. I am talking about repositioning the objects in my layout.
by repositioning I mean moving the objects according to the size of the screen. For instance i created my layout for a larger screen which looks great, but when i run the app on a smaller device (smaller screen) some of my User Interface elements were out of the bound of my screen.
There is no "best" layout. Almost all types of layouts will scale to different devices (Android is designed around this concept) other than AbsoluteLayout, which is deprecated anyway.
LinearLayout is best if you just have a row (horizontal or vertical) of content to insert. Using values such as dip values, fill_parent, or wrap_content will automatically adjust themselves to their content or screen size.
RelativeLayout, as Vladimir pointed out, is best for layouts where views are positioned relative to other objects within the layout. For instance, a TextView positioned beside a "Submit" button, is a common example.
FrameLayout is sort of a replacement for AbsoluteLayout; you can layer objects on top of each other, just specifying margin offsets from the sides of the frame.
TableLayout is, as it sounds, a layout for Table style design. You can have multiple rows and columns, and set certain columns to stretch to fit the size of the display, so that no matter the screen size, the layout fits as you designed.
EDIT: If you're having objects falling outside of the screen area, try wrapping your root layout in a <ScrollView>. This will allow the layout to be scrollable.
e.g.
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<RelativeLayout
..... //and so on
</RelativeLayout>
</ScrollView>
All Layouts are flexible in terms of size... the rule is: don't use AbsoluteLayout. That's all.
And with regards to the repositioning concerns... well, use always dips instead of pixels and you are good to go. Again, don't use AbsoluteLayout, the rest of the layouts should work fine on every screen size. Sometimes you can anticipate those "disappearing acts" by wrapping your layout in a ScrollView.
RelativeLayout is what you should be looking at. It easily resizes the elements relative to their neighbors. Just make sure to include drawables for all resolutions and densities
LinearLayout,RelativeLayout,FrameLayout are import Layouts....