I have an ImageView that has a picture. When the user does something, I want the picture to change to another resource.
I found this solution:
Creating animation on ImageView while changing image resource
But it first fades out the current picture and then it fades in the new one. What I want is that at the same time the first resource fades out, the new picture to fade in.
I was thinking about using 2 ImageViews, one to fade in, another to fade out. But I was wondering if it can be accomplished using a single ImageView.
(I don't want necessarily a fade-in fade-out animation... a merge/blend whatever would be ok too)
Thanks!
Finally used a ViewFlipper to switch between the two "images".
<ViewFlipper
android:id="#+id/view_flipper"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/background_level"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="#drawable/background_level_1" />
<ImageView
android:id="#+id/background_level_flip1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="#drawable/background_level_2" />
</ViewFlipper>
Related
I would like to use getLocationOnScreen to get the location of an ImageView, and then I would like to place another ImageView exactly at that place.
Assume they both are in the same layout. When the app starts only imgv1 is visible. The user can move and rotate that image. Then the user can press a button and second image, imgv2 should be placed exactly on top of imgv1 so it covers it. Both imgv1 and imgv2 have the same size.
For example, assume I have imgv1 and imgv2 as:
ImageView imgv1, imgv2;
int[] img_coordinates = new int[2];
imgv1.getLocationOnScreen(img_coordinates);
I wanted to use something like:
imgv2.setX(img_coordinates[0]);
imgv2.setY(img_coordinates[2]);
but this doesn't do what I need to do, which is to place the top left corner of imgv2 on the top left corner of imgv1.
Any other method that helps me to do so is fine too.
** Update **
This is the layout I have:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/tools_root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent">
<ImageView
android:id="#+id/imgv1"
android:layout_width="300dp"
android:layout_height="200dp"
android:layout_gravity="center_vertical|center_horizontal"
android:visibility="gone"
app:cameraCropOutput="true"
app:cameraPlaySounds="false" />
<ImageView
android:id="#+id/imgv2"
android:layout_width="300dp"
android:layout_height="200dp"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:visibility="gone" />
</FrameLayout>
The javadoc for view says that setX and setY will offsett the image from it's original location. It looks like what you want to use is setLeft and setTop.
https://developer.android.com/reference/android/view/View#setleft
If i have overlapping views I generally put them in layout and show/hide them. However if you want to dit via code try setting layout params of second image like:
lp.addRule(RelativeLayout.ALIGN_LEFT, image1.getId());
lp.addRule(RelativeLayout.ALIGN_TOP, image1.getId());
...something like it.
Positioning depends a lot on parent of Image views. Relative Layout would be correct choice.
Step #1: Put imgv1 in a FrameLayout
Step #2: Put imgv2 in that same FrameLayout, with android:visibility="gone"
Step #3: When the user presses the button, call imgv2.setVisibility(View.VISIBLE)
<FrameLayout android:id="combined">
<ImageView android:id="imgv1" android:layout_width="match_parent" android:layout_height="match_parent" />
<ImageView android:id="imgv2" android:visibility="gone" android:layout_width="match_parent" android:layout_height="match_parent" />
</FrameLayout>
Missing are sizing/positioning rules for the FrameLayout, which would be whatever you are presently using for your starting conditions for imgv1, presumably.
Alternatively, have one ImageView, rather than two, and change the image on the button click. For example, you could use a LayerDrawable (or the equivalent resource) to layer two drawables on top of each other, and show that.
I'm trying to make AppWidget shows rotation images which can automatically change every 5 seconds,and I think ViewFlipper might be able to reach this goal.
But I get images from server and can't just put them as ImageView in .xml file under nested ViewFlipper like this:
<ViewFlipper android:id="#+id/viewflipper"
android:layout_width="match_parent"
android:layout_height="match_content"
android:autostart="true"
android:flipinterval="5000" >
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/drawable1"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/drawable2"/>
</ViewFlipper>
I need to add images dynamically, and shows one picture at one time. If there's more than one image, they need to be shown on AppWidget by turns.
Hope somebody could help me with this, thanks!
I assume by "dynamically" you mean there could be an arbitrary number of items. What you probably want is AdapterViewFlipper. You can follow this guide for building an AppWidget whose content is backed by an adapter.
So, i wanted to put an image in background of my screen. My problem is that if i just add the image to "background" it will fill all the screen, and my image gets defaced. I could put as an ImageView, but the problem is that i have an expandableListView in the same screen, and i wanted the image to stay behind, as a background.
Any idea how to do this?
Can have 2 solutions: Put as an imagemView but behind the list. Or add as a background but resize it. How can i do it?
Here is what happened:
He is what happens if i put the image as an imageView:
Yes this is very easy to achieve with relative layouts
<RelativeLayout ... >
<ImageView ...
android:layout_alignParentTop="true"
android:scaleType="centerCrop“ />
<ListView ...
android:layout_alignParentTop="true“ />
</RelativeLayout>
With a relative layout z-index is decided by the order you declare the tags, so stuff towards the bottom of the xml is in front of stuff from closer to the top, when they are in the same position.
Use a FrameLayout (Inside FrameLayout view written on top will appear on top and so on)
<FrameLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
></ListView>
<ImageView
android:layout_width="your_width_in_dp"
android:layout_height="your_height_in_dp"
/>
</FrameLayout>
You can also place FrameLayout inside another layout.
I need to show an Image on ImageView & onClick of that Image , I wanna show another image on that imageView only with some Cube-like Transition Animation as shown in the below figure with "onTouch" .
I have been searching some examples on this site which , all are intended for an activity .I need to implement it for an ImageView .
Presently I am using some ViewFlipper with two images and trying to implement it,
<ViewFlipper android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/a"
android:layout_weight="1">
<ImageView
android:contentDescription="#string/action_settings"
android:id="#+id/alphaA"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/a"/>
<ImageView
android:contentDescription="#string/action_settings"
android:id="#+id/imgA"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/small_aeroplane1"/>
</ViewFlipper>
..........
like that I have 4 View Flippers upto now.
I need to know , how to add cube transitions for the above case. OR is there any better way to implement CUBE TRANSITION between only two images
I think these two links will help you in your future projects.
1) https://code.google.com/p/transitionviewpager/source/browse/
2) https://github.com/jfeinstein10/JazzyViewPager
You'll have to use ViewPager,
check https://github.com/jfeinstein10/JazzyViewPager
or here is a ready ViewPager class with 3D cube animation
https://github.com/inovex/ViewPager3D/blob/master/src/de/inovex/android/widgets/ViewPager3D.java
I'm developing an app which contains an image at the upper half of the screen and a gridview in the half below, like this:
<de.test.gridview.Image
android:id="#+id/image_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:fadingEdgeLength="0dp"
android:scrollbars="none"
android:visibility="gone" />
<de.test.gridview.DraggableGridView
android:id="#+id/grid_view1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/topnews_container"
android:background="#FFF"
android:gravity="center"
android:numColumns="auto_fit"
android:stretchMode="none"
android:tag="grid_view_tag" >
</de.test.gridview.DraggableGridView>
The Image is set to visibility=gone and set to visible in the code manually later on.
When I now drag on of the childs of the gridview I cant be able to drag them over the image in the upper half of the screen. They are always behind the image, but never in front of it. I've tried to use
gridView.bringToFront()
and also within the gridView I tried this function. I also tried this on the children of the gridview with gridView.bringChildToFront(child). But nothing worked.
Does anybody have an idea?
I guess view with property set to View.GONE is not operational via bringToFront(). So I believe the following will work (if you are trying to bring the grid to the front/top of z):
gridView.setVisibility(View.INVISIBLE);
gridView.bringToFront();
But its looks like you want to bring imageView to the front (making gridView behind instead of front). If so you need to:
imageView.setVisibility(View.INVISIBLE);
imageView.bringToFront();