I'm wondering..
1)is it possible to set an imageview's resource to the URL location of an image?
2)is there a way of setting the x,y co-ords of where on the screen to draw the imageview?
3)How would I run a check to see if the space is taken up by another Imageview (must specifically be an imageview)
4) How would I make the Imageview "clickable" e.g if the user clicks the image it'll do something?
5) How would I dynamically create imageviews? E.g if a condition is true make another imageview
Perhaps I'm going about this wrong so I'll explain better what I'm looking to do.. basically I want to draw images on the screen which are located at URL's. I want to display N amount of images (There will be conditions which will decide how many images I'm displaying, so it'll have to be dynamically created) each image should take up approx 50x50 screen space. There will be other conditions to where the image should be displayed.. If an image exists at a certain co-ord it shouldn't draw over it, when the user clicks the image something else should happen.
Hopefully this makes things clearer.
Thanks.
Not directly. You can download image afer program was started, then convert it to Drawable and display on screen. But you cannot assume user always enables data transfer, so often image won't be downloaded at all.
Yes, but much better is to use Layouts - different handsets have different screen resolutions and desinty.
No simple answer - it depends, how you prepare and display screen contents.
((ImageView)view.findViewById(R.id.imageid)).setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
//something
}
});
It sounds like you don't need ImageView (the graphics component used to place image in various layouts) itself, but rather some kind of canvas. Anyway, see:
How to add 3 images in a canvas in android
Drawing to the canvas
Related
Considering to have this seek bar:
.
I want to do the same thing with my image. I want to select a part of this image from 0 to 100% and track this percentage.
For example, my original image (0% selected) is all grey. If I scroll a bit with my finger on the image, I can select for example 50% of the image and change the style color to evidence this change.
It is important for me to track this percentage because I need this to do other things on my personal project. How is it possible to do that with android? Thanks in advance.
Yes, it is possible to do that with android.
You can grey out an image with the code provided in Graying out a BufferedImage
and you can get the touch position with the code provided in How to get the Touch position in android? for any android app.
Now, if you know where your image is in the android app, lets say its between ymin=0 and ymax=640 and you know that the finger is at y=320, you can just divide y/ymax and get the percentage (50% or 0.5) of the image that is to be shown. Now you can grey out 50% of the image, et voila.
I'm new to LIBGDX game development, and I have faced my first problem. I've created 9.patch drawables (buttons) using texture packer. This drawables can be used on low density and also extra high density screens and quality is the same.
If I run my project with that drawable on desktop project the image shown is okay and perfect size. If I run project on low density android device, drawable becomes huge (almost half of the screen). And also If I run project on extra high density android device the button becomes really small.
So my question is, how to handle drawables in LIBGDX, so the ratio (screen:image size), stays the same no matter resolution/density..?
If your button is a text button. Change the font of your text.
If you are using image button, this might help you
It kind of depends on what you're drawing...If you are just drawing an image, I've found it easier to specify a float width and height in the last 2 parameters of the draw method. If you are using a camera with a fixed viewport size, you can simply use a fixed percentage of your camera viewport so it will always be the same dimensions and draw like this:
batch.draw(drawable,x,y,screenwidth * 0.5f,screenheight*0.5f);
However, if you are using buttons or some other widget inside of a table, you should specify the cell size and it should automatically be resized based on the size of the table cell. Something like:
myTable.add(myWidget).width(300).height(200);
Post up exactly what it is that you need to draw if you get a chance and it will be easier to figure out what needs to happen.
This is the scenario:
I have one image background set on an activity. On this background, a rectangle has been drawn (in other words, one image depicting a rectangle). I need to display text WITHIN this rectangle.
Right now, I have one solution in mind: since I'm going to optimize the UI for most screens (incl. tablets), I'm going to customize the main .xml layout for each screen size (multiple .xml layouts). Thus, I can manually set the place where the text area goes within the rectangle (+ its size).
I am most certain that this solution is NOT good. I'd like to hear some suggestions from more advanced developers. What would an elegant way of placing text over a background image showing a rectangle, so that the text stays within the rectangle's borders be?
Because I need to set particular positions for other UI elements (centered buttons (vertically/horizontally), I am currently using a Relative Layout.
By default if you have used dp as dimensional measure, your app should in theory work fine for all resoultions. Android by default scales the screen to fit different screens. AndroidDeveloper You just have to make sure that you have different images for resources (Rectangle image). There is another post in SO which you might be intrested to look into link
Cheers
RIchie
Well i have a circle image that i am using imageview to show in the app
I need someway to make parts of this image interactive like event should fire depend on which part of the image the user is clicking , i.e. if user is clicking on the center of the image or on one of the pie slices of the circle image
how this could be achived ?!
One way would be slicing the image into the parts, then assigning a clickevent to each part with the appropriate reaction.
the other way could be to check on the clickevent where you have clicked (x,y) and check if it is in a range you defined as an area if it's in there.
or you have different colors of the slices, you then get the color of the clicked pixel and evaluate where it belongs to
I'm having a problem with positioning images,I need to position a lot images over another larger background image.
An image Like this
I have tried Absolute but it does not keep the position of the image say I wanted to put a clip art image of a board pin over the background image and need it pointing at a sun and when it's clicked I get a popup dialog,
but then when I change the size of the emulator screen the clip art image is not at the same position I wanted it on the background image.
I first tried just putting the clip art on it with a image editor and used onTouch Listener but that didn't work out when I changed the size of the screen with the x and y coordinates. And tried Absolute Layout and that doesn seem to keep the position.
any ideas would help me big time thanks
AbsoluteLayout is deprecated, so it's probably best to use relative layout alongside with dp.
You could use relative layout so you can use layout_below="#id/view1", android:layout_toRightOf="#id/view2", and android:layout_toLeftOf="#id/view3". You can also use android:layout_marginLeft="10dip", android:layout_marginRight="10dip", android:layout_marginTop="10dip", and android:layout_marginBottom="10dip" to move the views left/right and up/down relative to their current positions. There is also ALIGN_PARENT_LEFT, ALIGN_PARENT_RIGHT, ALIGN_PARENT_TOP, and ALIGN_PARENT_BOTTOM. Click here for more properties.
You can manually calculate visible width and height of the image by using its drawable's getIntrinsicHeight() and getIntrinsicWidth() and then set Image's scaleType to FIT_XY (this saves image's ratio, and also makes its size correct, while FIT_CENTER does not).