I was looking at my layout on different screens of the xml noticed wrap layout looked the same. So, I wondered if the above was true. Help would be great.
In Android Wrap Content attribute adjusts the element depending on its' content.
It adjusts its' size and display style according to different dpi values and screen sizes automatically so that you don't need to manually configure your element.
i'm not sure if i have understood your question, but the "wrap_content" is like a div in html/css, so if you dont set a proper padding it just leave 1-2dp around the argument.
Related
I was wondering how to make my interface's TextViews, ImageViews, Margins, etc... look the same on all devices no matter if I'm using it on a phone or a tablet. I was told that using fragments would help, but I don't seem to understand. Sorry for the babyish question...
You can use constraint layout and set the widget's height and width according to the screen's width and height. Or you can have different layout files for diffrent screen densities.
I'm developing android application using Titanium 3.X. I need to add an image and a label (name) in a way that label is next to the image in same row and both should be right aligned. The problem is label text which represent a name is dynamic. So I can't set right property for the image view. I need to do this in a way which compatible with different devices (Screen sizes). I have given my font size as 11dp.
right property for image can be calculated by some algorithm which accepts font size, device screen width etc. But I couldn't identify it. Can anyone suggest me a way to resolve this ?
In this situation, I would add a view to wrap the image and label. I would set the view's layout to horizontal. I would then right align the view.
You should use a layout that will do the computations for you.
The RelativeLayout is quite useful in such situations. When you construction it in XML there are attributes like alignParentRight or layout_toRightOf that should prove useful. Don't forget to set the width of the TextView as wrap_content.
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.
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've been playing about with the layout of a view with Android (lets say within the MainActivity) and I'm looking to create this sort of layout using 3 ImageView's (where each block represents an image):
This is rather easy to pull of using LinearLayout's but only if you specify the exact size and position of each ImageView. This then obviously causes problems when looking at different screen sizes.
Using AbsoluteLayout looked like it was going to work at first, but I've read that it's deprecated and it still causes problems with different screen sizes.
Then there is RelativeLayout, which I've tried using with DroidDraw, but it doesn't seem to get me very far when I implement it :(
So, does anyone have an ideas of how to achieve this?
EDIT: I've got close to doing this using dp instead of px but this still gets screwed up when using larger resolution devices! :(
Thanks
Romain Guy does something very similar using RelativeLayout. Android Layout Tricks #1
One solution is that you could use a TableLayout with 2 columns, and then in the second column embed a second TableLayout.
DroidDraw doesn't always show exactly how it will work when it runs 100% of the time I've noticed.
You can do this with a horizontal LinearLayout: add the green first, then add a vertical liner layout for the blue and orange and give each an appropriate weight (like 50 and 50).
You can still use LinearLayout but make the width/height in dip units. Thatvway it should look the same on any supported screen size. Alternativly, you could use the weight attribute instead which is probably a better idea for this case.