Android imageview not behaving with setAlpha for transparent image - android

I have a view that I am dynamically adding two ImageView elements to at runtime before adding the view to the parent container to display it. On drag events, I want to set the image transparency to hidden or shown depending on the direction of move. I am trying to use imageView.setAlpha(0) to make the image invisible but even though the code is being called, the images stay visible or partly visible from when their alpha value was changed earlier to say 0.5.
Is there any reason an ImageView would refuse to trigger on a programmatic setAlpha()?

Set it to 0.0. To change the opacity, you need to use the setAlpha(float) not setAlpha(int)

Related

background drawable does not fit in bound of TextView in Android

I made a TextView which has attributes of background, gravity and so on.
and i made a drawable resource file for the TextView's background.
and this is the xml.
and i added the drawable resource into background of the TextView.
but the problem is, the background doesn't fit in Textview's bound.
please look at this photo.
there is a gap very slightly.
the background color area is upper than TextView's area.
so i tried to use includeFontPadding attribute but it didn't work.
how can i fix it?
I would advise you to check this on real device/emulator, not on preview in AS. use Show Layout Bounds option from developer options for verification, make some full-resolution screen shot and check on it. it will be properly placed
content of any View, including its background, is always places inside its bounds. really, always, its just impossible to get outside with a single pixel (due to layout building and drawing mechanism)
Nothing is wrong with the code. In the Design Editor, it shows like this when we use any background drawable with any view. There is not any kind of a glitch.

Setting points to click on my Map ImageView

I have a blueprint image in my app. The user will be able to click on some pre-established points and after they click on this point, a dialog will show some information.
My question is how I add the specific points in my ImageView Blueprint and the click function on these points?
EDIT 08/08/2014
My ImageView now has pinch zoom and the app will have more than 1 blueprint.
Thanks and regards!
You could go about this multiple ways. If your blueprint is full screen on the users device then you could create your own custom layout to encapsulate the imageview and override the ViewGroup's onDraw an onTouch methods to add your points. Then you could have a method like
public void addPoints(float[] points) { // do something here }
Another option is to extend the ImageView itself and make your own custom imageview and then again override onDraw and overlay the points ontop of the image. YOu can set the bitmap (your blueprint) as the background and then drop ontop of that. You would have to figure out where the specific points are though depending on the size of your image and the device, unless you set the size to be pixel density independent.
The first thing that comes to mind is you could use RelativeLayout in the XML file. This allows you to layer elements on top of one another if you so choose. You could use this to position invisible buttons above the image.
With RelativeLayout, each button could be positioned using its margin attributes, and it should be fairly simple to make the button invisible by assigning the transparent color for its background and providing no text.

image animation cropped by layout bounds

I have an image that gets scaled from large to small as it spins. It's mean to be a fancy animation to simulate a tile being place on a board. The animation works as expected except for one thing: This image is cropped.
Each row of tiles is inside of a Horizontal LinearLayout. Each LinearLayout is inside of another LinearLayout (Vertical). This give the board. Sadly, the image animation is getting cropped to not excede the bounds of the parent layout. I don't want that. I want the image to be displayed and animated as if it's on top of everything else. I want it to exceed the layout.
Any idea how to fix this?
Here's a couple of screenshots:
Your image is constrained to fit within it's parent view as per design. You might want to use a canvas to hold all your tiles instead (keep in mind the bounds of the canvas for the corners otherwise you will have the same issue), or look into other layouts that might be able to accommodate your needs.
From: http://developer.android.com/guide/topics/graphics/view-animation.html
Note: Regardless of how your animation may move or resize, the bounds of the View that holds your animation will not automatically adjust to accommodate it. Even so, the animation will still be drawn beyond the bounds of its View and will not be clipped. However, clipping will occur if the animation exceeds the bounds of the parent View.

Add buttons to specific positions on an image

I was trying to add some buttons to some specific positions on an image. I am making use of webview to display the image because it embeds zoom in/out function; I have tried AbsoluteLayout to put buttons on it but when I zoom in, the button moved..
What should I do then? How can I make the button stick to one position of an image no matter how I zoom in and out?
It seems impossible to get the desired effect if you use WebView, since WebView's scaling does not affect the child view added to it.
If you are working on API 11+, you can use a ViewGroup such as FrameLayout to hold the image and the button, then call View.setScaleX(float sf) and View.setScaleY(float sf) on FrameLayout to scale it, so that all of its child will be scaled too.
I don't have a good solution for API level before 11, since View class does not contain transform information before API 11, maybe you can just recursively adjust the LayoutParams of all the Views to get the effect, I didn't try it, though.

Android: How do you scale multiple views together?

I'm trying to layer graphics one top of each other, like an icon over a background, with the second layer (icon) at a certain pixel offset from the top left corner of first layer (background). Since each layer will eventually have its own animation, I'm placing each in its own View.
For my implementation I have two ImageViews, one for each layer, inside a RelativeLayout, which in turn is inside a ScrollView. ImageViews are positioned using layout_margin relative to the top left corner (0,0). The first ImageView is larger than the screen (background), while the second ImageView is smaller than it (icon). ScrollView automatically resizes the first ImageView (background) since it is larger than the screen, it does not resize the second since it is smaller (icon).
I need both of them to scale together, and I also need the positioning of the second layer over the first layer to adjust itself accordingly. This actually works well in a layer-list, but due to the animations I am forced to use Views. How can I scale and position multiple Views together, or do I need to build my own class for something that seems like it should be fairly basic?
Thanks in advance.
I had a similar problem in my android application. Android has introduced new set of API's to help us on this, setScaleX() and setScaleY().
Just call layout.getParent().setScaleX(); and layout.getParent().setScaleY();

Categories

Resources