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.
Related
I want to set one textview over an image, I can use framelayout and I can set layout margin, bottom, right and left for the specific place. But the problem is it varies from device to device. The alignment of the textview is not proper in all devices because of the screen size. Is there any way to set text view dynamically on image in a specified placement? The image looks like below.. Here I need to set multiple text view to update that value. These all text fields I want to be set dynamically.
Thanks in Advance....
Is there a more precise way of arranging components in App Inventor than using the Vertical/Horizontal/Table Arrangement formatting elements?
I want to sparsely position about six buttons across my app screen - all different sizes.
Thank you in advance.
the short answer is: no
well, additionally you also could use empty labels as delimiter between components...
another answer is: you could use a canvas and sprite components instead of buttons. You can define sprite positions exactly at x/y coordinates of your canvas.
However keep in mind, that there are different Android devices with different screens sizes and resolutions, so normally you wouldn't set buttons exactly at x/y coordinates to avoid strange layouts for e.g. smaller or larger devices.
The bit longer answer is to use labels as spacers.
Example:
Need to center a button at the top of the screen.
Add horizontal layout with 2 label texts and button in center inside of the layout.
Click each text label and remove the actual text from right side properties menu and choose fill parent width and height.
This centers the button because the layout automatically assigns one third size to each.
Labels are the best, but longer coding answer.
I'm developing an android calendar app so I need to align the days in a grid-like style. I'm using the API Level 8 so I need to align them by margins. But when switching to Bigger screens the numbers get to the left of screen and do not cover the whole screen.(I know that is because I use dp as a unit for my margin-left). Is there something like CSS % (percent) in Android Layouts?
Try this
android:layout_weight="1"
on each element in that section. It should space evenly.
It's weight attribute for views inside LinearLayout. Here is a good explanation what it means. But you can use it only to set view sizes, not margins. However you can put your view into RelativeLayout, place this layouts to take all available screen width and set attribute centerInParent=true in your view.
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.
I have an application where I want to achieve a layout where the product image will be in the background and top of that to the right bottom, I want to place the price of the product and to the left bottom I want to place an add button.
Should I use frame layout or relative layout ???
As a practical rule, I think it's up to you. I personally tend to use RelativeLayouts because they're more flexible, but you can achieve the same effect with either.
This SO post explains the performance differences between the two layouts in more detail: FrameLayout vs RelativeLayout for overlays
Relative layout: When you have relation between siblings or parent.
Frame layout: When siblings are placed independent of each other and are only dependent on parent.
Based on your situation, you can opt in of any of these.
My advice, If you have specific size for your background for each device, then go for relative layout, and set the background to your image. Because when using background in RelativeLayout, It'll fit the size of the relative layout itself, whether the image suits the size of the RelativeLayout or not. (Can be stretched/pixelated/Not properly added)
If you're not sure about specific size, you should use FrameLayout, with ImageView, that handles the ScaleType, which can be centerCrop, and it'll fit the layout in good shape.
And for the TextView, use layout_gravity, which will handle the position based on the parent layout.