Im facing the next problem: I have an imageView that change the size programmatically because de density hdpi has a 480x800 resolution. I change the size with layoutParams.
After I change the size, I want to position the imageView. When I position the view for example to the coordinate (0,0) I saw that between the imageView and the limit of the screen is a little space, like 25 inches. The imageView moves to other place and when I want to position it again to (0,0), the space between the imageView and the limit of the screen disappear. Why is happening that? I need to fix that because the first time is showing wrong, I don’t want the space!
Hope your understand
Greets
Related
My task is to allow user to upload an image and let user to put a custom view anywhere he clicks. (Like taging a pic on facebook) That is simple by getting the touch location and dynamically adding view to a relative layout and setting leftMargin and topMargin.
But I want this custom component to get drawn in the 'exact' same position in every android device.
For example; Think that you uploaded a picture into your profile and tag someone, other people who look at your pic with different devices should see the tag in the exact same place relative to the pic.
I know that I have to take account of screen density as well but don't know how to manipulate x, y according to that.
Look at the example screenshot:
(Blue box is put by user click)
This screenshot is from a test device with screen density 1, another device with density 1.5 shows the blue box in a different position.
(Images Updated:)
This is a test code:
icon = new ImageView(getActivity());
icon.setBackgroundColor(getResources().getColor(R.color.blue));
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(30, 40);
int density = this.getResources().getDisplayMetrics().density;
params.leftMargin = (int)(posX/density);
params.topMargin = (int)(posY/density);
Think that you uploaded a picture into your profile and tag someone, other people who look at your pic with different devices should see the tag in the exactly same place.
Then you do not want to be placing "a view to absolute X, Y for all android devices".
For example, suppose we have two devices, A and B. On Device A, your image is a small phone, and the image happens to be rendered at a size of 480 pixels high by 270 pixels wide. The user taps at a position that happens to be 80 pixels down from the top and 70 pixels in from the left.
Device B has a screen approximately the size of the country of Turkey. More specifically, your image is rendered at 1600km by 900km on an -mdpi screen density, in a portrait orientation, meaning the image is around 10,078,736,000 pixels high by 5,669,289,000 pixels wide.
You do not want to be putting your marker 80 pixels down from the top and 70 pixels in from the left. That will put the marker almost in the upper-left corner.
Assuming that you arrange to show your image at the same aspect ratio, you will want to save the percentages that the marker is from some corner. In this example, 80 pixels from the top is 80/480 or ~16.7% from the top, and 70 pixels in from the left is 70/270 or ~25.9% from the left. You would then apply the percentages to the size of the image on another device, and so show your marker ~16.7% from the top and ~25.9% from the left on the Turkey-sized screen. Or on a tablet. Or on a larger phone. Or on a TV. Or on whatever you are choosing to use.
Say I have a background image as such.
http://i.imgur.com/rRCtzyl.png
I want to put a button or text right inside the white box. My text or button must scale and fit the box perfectly when the image is scaled according to device screen size. The image does not fit the screen vertically so it is scrollable. I know that I need to put them in a group if I want them both to scroll together.
But how do I place the button inside the box? Since its scrollable I dont know the exact x and y values of the box. Not to mention these values will change according to device screen size. And how do I make the buttons scale to fit the box with all screen sizes?
This image is only an example. Of course I wouldn't have a problem if I drew the box myself programmatically. I would know where to put the button. Assume I dont know the coordinates and the size of the box since I didn't d
If your box object is called box, set the button to the box.x and box.y like this:
object1.x = box.x
object1.y = box.y
The scroll aspect should not matter if you put the button and image in same group and scroll the group. Then all you need to do is position the button relative to the image once, the rest will be taken care of by corona.
What will matter is the screen resolution. One way of tackling this is to view the image at full resolution and compute at what x and y pixels the box is located. For instance,
image: 200 x 300 pixels
box top left: 100, 100 (pixels from top left of image)
box width height: 20, 60
Then you use ratios: top left of button box is at 0.5, 0.3333 of image size; the button box width is 0.1 and height 0.2 of image size. Then when you start app, you compute what will be the image scaling factor based on actual resolution and you apply that to box coordinates:
device 300 x 400:
image will be scaled 1.5x in width, 1.333x in height
so button box should be at (200*1.5*0.5, 300*1.333*0.333)
with width 20*1.5 and height 60*1.333
I have a problem in animating image like marquee of a TextView.
For example, if the image is translated to X-axis by 50 pixels to right, the 50 pixels in the left is will be filled by translated 50 pixels (the width of image is no changed).
Original: xxxxx50pixels, after Changed: 50pixelsxxxxx
Is there anybody can suggest me a solution?
Thanks for your help.
If you want animation with only one image then you can use .gif image for marquee effect.
I have an image which is actually 393 x 21 px, which I would like to set on the bottom of my View.
The problem is that, even if i set the width and the height to fill_parent, my image stays very small in the middle of the screen bottom and on the left and the right I have an empty field.
I can resolve this by reducing the Image width size mannualy but is ther any other solution whic could set the image in fullscreen ?
Thank you.
//in your xml Image attribute as
android:scaleType="fitXY"
or //using thru programatically
imgview.setScaleType(ScaleType.FIT_XY);
I want to identify a certain part of an ImageView -- based on the actual size of the image regardless of how the image is scaled for the particular device.
Example: I have an image that is 480x320. I want a rectangle that (at this size) is defined as
Rect(10,35,20,50). What I'm wanting to do is figure out how I can define this rectangle relative to the actual size of the image when it scaled and displayed on the screen.
Can you just scale each part of the rectangle? For instance, if your image is displayed at 2x -- 960x480 -- then would the correct rectangle be (20,70,40,100)?
Use percentages from a pivot point: the top-left or the bottom-right.