I'm new on the Android development and I have some problems to place views in a precise position, indipendently from the resolution or the screen size.
I have a background image and I would like to put TextViews/Buttons in a specific position without use dip coordinates.
I use a Frame Layout to put the background image and the views on different layers but the problem arise when I change screen resolution or screen size, the elements change position.
Do you know how I can solve this issue?
Thanks
Related
This might be a dumb question but I'm using unity to build a double pendulum app and because not all screen sizes are the same the UI buttons get moved around and don't scale to match the phones screen size. I attached a few images to show you what I mean.
Notice how in the third image, the return button overlaps the other UI sliders. I think the issue is that the pixel distance from the top of the screen doesn't change given new orientation. Is there a way to keep the spacing proportional?
On your canvas object, set it to Scale With Screen Size then, set the Match property to 0.5. This way the canvas will scale with both width and screen height.
If you need more info about Designing UI for Multiple Resolutions, check here
Well in your parent cancas object in the inspector,the 2end setting there a a drop down. Click it than a magical setting scale with screen wil be ther.👍
I have created UI and I want to make it independent of screen size of screen reslotuion... but I am not able to find any perfect soltution for that.
I have tried to set posiotion of view using ,
1)Displaymatrix.widthPixel and Displaymatrix.heightPixel
2)view.measure(0,0);
view.measureHeight();
view.measureWidth();
and try to set position of view1 with respect to view... but it looks at different places on different screen size devices.
please help me to create a common UI which looks same on all size of devices.
Thank you in advance
I am attempting to make an 8x8 matrix of coloured squares on a black background in a layout that is limited to portrait only. I need the squares to all be equal in size, and the overall matrix to be 60% of the screen's width and of equal height. I also need to control the colour of each square dynamically as a result of my code, call it a pattern setting code if you will. Here is an example of what I need the final product to look like:
Screen example
I have been researching different ways of doing this and was hoping for some advice on the best approach. Here are some ideas I had:
1) Use GridLayout (not GridView) and set the background of each cell to the required colour. This shouldn't be difficult to control with java, but how do I enforce the correct dimensions? Would I need to fill each grid cell with something of a certain size, or can I use layout_weight attributes to control the dimensions?
2) Use a combination of RelativeLayout and LinearLayout with ImageView and display locally saved images of coloured squares. Can I use layout_weight to control the size of these images, and if these images were too small would they be stretched to fill their required dimensions? (I'm thinking of larger tablet screens.)
What I really need from someone is some sample code to implement a very simple version of what I need (for example one square in the centre of the screen that I can colour-control dynamically). Obviously I can then expand it to my specific requirements. If more details or code are required I will happily post them.
Perhaps you could just create a custom View object, and render the appropriate bitmap in the onDraw method? Seems like overkill to use layout objects, unless you're planning to do more than just render squares of colour?
Edit: Alternatively, I once used the info in the following posting to programmatically build a layout grid. It's not exactly what you need (it generates as many horizontal 'cells' as are necessary), but should make for insightful reading on manipulating layout dimensions:
Line-breaking widget layout for Android
I'm working on a project where I have a static image as background and I need to put some Views on specific locations relatively to some elements that appears on the background picture.
When I'm using FrameLayout or RelativeLayout and trying to measure the exact dp from the corners I get different results for different screens sizes and the relation with the background image is lost.
I try thinking for solutions. Maybe I need to measure the image background size on the fly and then try to calculate the exact position? Or maybe put some "water marks" in the background images and get the correct positions by scanning the bitmap on the fly.
What is the best approach?
I have an Android Gallery setup on a layout with both the width and height set to Fill_Parent. This works great for smaller screens, but as the display size grows into the tablet sizes, the Gallery stretches to a layout that is taller than it is wide. At this point, there are no more side images on it - that is, just the main selected image is visible. I want to have at least a small amount of the side images visible so the user knows the view is scrollable.
Does anybody know how I can do this?
Is it possible to maintain an aspect ratio while still using fill_parent? Is it possible to set the Gallery view to show a certain amount of the side images? etc?
Thanks!
The Gallery class is pretty limited and personally I tend not to use it. Have you considered using a ViewPager instead?
AFAIK, If you are using
android.widget.Gallery
then the implement a custom adapter to the view, and set a layout wrapped to each items inside the gallery view. If you still don't understand what I just said, I would try to generate some reference code.