Android Layout On Top of an Image - android

I am struggling with a Layout Problem on Android. This is very simple to do on the iPhone, but with the various screen sizes and the Layout classes available. I am having a hard time doing this.
One thing that I have noticed is that setting backgrounds on objects in the xml really messes up the layout on the device. I generally have to put in a FrameLayout and an ImageView to get a background.
So Am trying to get to this. http://www.calidadsystems.com/images/AndroidListItem.png (Sorry I don't have enough pts to post the image)
his is a status view and is an item in a List View. There are 8 TextViews that need to be set. Each of the 222 fields will change. The current background has the colors in there at specific locations and I am trying to line up the Labels and TextViews to get the picture below. I built this one with AbsoluteLayout which is deprecated, but it also does not work very well on the device.
I have constantly struggled with the layouts on Android. Does someone have some good sample code that could do this?

You're probably going to want to use a RelativeLayout. You can use the android:layout_alignTop="id" attribute to make the rows be in line correctly. And android:layout_alignLeft="id" for the columns. Other than that its just a matter of playing with the android:layout_marginLeft="XXdip" attribute to get the space between them how you want it. Check out this page for an overview and examples of all of the Layout types. Here is some more sample RelativeLayout code. And one more page with another example. RelativeLayout is a bit tricky to get used to but once you've used it a few times its pretty easy to understand and get the Layout that you want. The benefit of it is that your UIs look nice on several different screen sizes when you define them this way.

Why not just composed the layout in a table layout and set the table layout's background to a custom made graphic you make? This should work well with you. Specifically the design of your design would be like 4 columns with x rows. Then using the strechcolumn property, you should be able to accomplish what you are trying to do!
If you scale the graphic properly, then you shouldn't have this problem overall.

Related

Android: Selecting Layout/ How to format Design for Calculator

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!

How to make image and text closer together in a button?

In my project, I have a 3x3 TableLayout consisting of nine different Buttons. Each Button has an image drawable above it and a small string of text below it. To be clear, the drawable and text are the Buttons using the "drawableTop" and "android:text" variables defined in XML.
I'd like to know that if it would be possible to move the drawable and the text closer together because the UI looks a bit off on big screened phones.
App on Nexus 4
App on Nexus 6
I realize that I will have to make different XML layout files for small phones, phones, small tablets and big tablets. But Nexus 6 is, as I classify it, a phone so I will probably not be making a separate layout file for it.
Any feedback helps unless you tell me that I need to use a LinearLayout with an ImageButton and TextView in it because I've already tried that and it didn't turn out that well.
When it comes to this, I usually use two views, one for the text and one for the image and put them into a ViewGroup, which then gets assigned onClickListener. This gives me more freedom and customization with the downside of lowering performance a bit.
But to answer your question, you can use android:drawablePaddingin conjunction with android:paddingTop to control the space between the image and the text.
Well the simple answer is probably mess around worth the text view's top padding. If that's not working for you the other solution is using the relative layout which is intended for such cases. That way you can keep the visual effect you're looking for while keeping the layout structure flat which is good for performance.

auto layout in android

Good day, i am developing an android app which generates comic like albums, i need to fit this comic to any screen width but i have trouble doing it coz of the layouts, its very odd and doesn't seem to be aligned with one another, here :
those boxe are composed of FrameLayouts which contains and ImageView (back), the frame which is a PNG (middle) and a TextView on top of the frame image. So basically the design is very complex and odd, I've heard that there is a way to make this fit automatically on every screen on IOS, they called it auto layout i guess. Is there a counter part of this on android? Thank you.
Try using a GridLayout. You should be able to achieve what you're trying to do. There's a good blog post here.

Android SDK, Placeing widgets/buttons etc at will?

Hey Im new to android developing and I have a quick question. Is there a way to place buttons where I want them on the view? Right now they only seem to be placed where there is specific spots for them. Why cant i drag and place them where ever I want like in the iphone sdk for example?
Is there a way to do so or does this functionality not exist? thanks.
Android (eg. similar to Qt) uses a concept of layouts. This is especially useful when you're creating UIs that can be displayed on different devices with different DPIs, different screen resolutions, etc.
So instead placing your buttons at pixel coordinates you put them, independent of device screen resolution, into layouts.
Read more in User Interface documentation. Using Eclipse ADT plugin you can visually create layouts. You can even embed one layout into other, creating eg. LinearLayout in RelativeLayout. This gives much more possibilities of creating screen scalable applications (one app on phone and tablet for example).
There is AbsoluteLayout, but that class is deprecated. The recommended strategy is to use a RelativeLayout (you can control the position of views by setting layout margins) or build your own custom layout class.
An android UI screen is build for various screen sizes , due to which you can not specify an exact location for the UI component .
Android instead uses the concepts of Layouts where each layout has a different behavior. Here are a few of them.
LinearLayout aligns all children in a single direction — vertically or horizontally, depending on how you define the orientation attribute
TableLayout positions its children into rows and columns
RelativeLayout , one of the most used layouts , lets child views specify their position relative to the parent view or to each other (specified by ID).
Android uses layouts to design the UI. For example, a vertical linear layout stacks one element on top of the other.
AbsoluteLayout is the most precise, but it's also harder to maintain and can get messy.
I recommend RelativeLayout. It positions UI elements relative to other elements.
If you don't really need that much precision, one more option is nesting layouts within layouts. But doing that too much gets messy and RelativeLayout becomes the better option.
A UI element's position is determined by the layout you choose. See this link.

Android View Design Issues

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.

Categories

Resources