Trying to rotate my LinearLayout for about 270deg, but view get's cut off.
layout.rotation = 270f
Also tried to set layerType but doesn't work also
layout.setLayerType(View.LAYER_TYPE_SOFTWARE, null)
Did i miss something?
How do i can rotate it properly?
Related
I'm new to android, and I am currently working on a simple connect three game, I have nine ImageViews which contain transparent images, when the ImageView is clicked, the resource is changed to x or o.
I've tried adding more animation, and setting resource to null rather than a transparent image, but it didn't work, only restarting the activity seems to fix it.
public void oneClick (View view)
{
//image view onClick
ImageView one = (ImageView) findViewById(R.id.one);
one.setImageResource(R.drawable.x); //setting x or y
one.animate().rotation(180).setDuration(500); //animation
}
Here's how I reset the images,
one.setImageResource(R.drawable.transp)
After this, if the onClick activity is called again, the image is set.
However the animation doesn't seem to work.
What am I doing wrong?
My image was rotated 180, so it wasn't rotating again, the simple solution was to reset the orentation of the image then run the rotate animation again, which seems to have fixed it!
clicked.setImageResource(R.drawable.x);
clicked.animate().rotation(180).setDuration(500);
after this
clicked.animate().rotation(0);
now if I use the rotation animation again, it seems to work!
This is a simple fix. Simply add .start() to your animation. It should look like this afterward:
one.animate().rotation(180).setDuration(500).start();
I'd like to create a textview that contains a blue line as it's background just like in the image I provided. You can also find it in Google calendar when entering appointment info.
I previously tried using 9patch images to stretch the line horizontally and keep the vertical scaling the same. But that does not work. I'd like to also use this in other view to provide my own background to other views. Any hints?
Thanks you in advance!
I believe that you are looking for the EditText layout item, not TextView. It will automatically change the line to the blue color when the user places the cursor there, otherwise it will be black.
you can use a relativelayout for your edittext, and for the lines, a view 1dp high at it's bottom (width matchparent so it stretches) , and two 1dp wide views at its sides, that'd accomplish that effect (as high as you want them).
I am trying to make a simple app just to understand better how to use Touch events on Android. Right now, my Activity just moves an ImageView to the coordinates of the touch on the screen (the MotionEvent's coordinates). I could manage to do this by applying a simple trick to set the new position of the image to a value that is made of the touch coordinates relative to the position of the image (getX() and getY()). The dx and dy variables are responsible to store this relative values so the touch keeps constant within the image.
Now I want to put 2 ImageViews in the Activity and have only two fixed spots for ImageViews and once the user drags one ImageView over the other ImageView's center, the two images switch places, but to do that correctly I would like to get the real coordinates of the image center. I commented the parts of the code that make it work correctly to show the issue. As you can see in the first picture when the view is created, the Image Coordinates are simply (0, 0), no matter where it is (as long as the initial position is defined as a layout parameter like CENTER_IN_PARENT).
As you can see in the second picture and as far as I observed ImageView's getX() and getY() return the coordinate as if the top-left corner of the image was in the top-left corner of the DISPLAY when the image is located at the top-left corner of the ACTIVITY WINDOW.
I would like to understand why that happens and if anyone knows how to actually get the coordinates of ImageView that can be directly compared to the coordinates of MotionEvent.
Pictures:
FIRST PICTURE
SECOND PICTURE
I still don't know exactly why getX(), getY(), setX(), and setY() do not represent the position of the View on the screen, but I figured out how to get the actual location of the view objects on the screen: getLocationOnScreen(coordinates). Where coordinates is a 2 position int array (int[2]).
For example, to get the real value correspondent to the top-left corner of my ImageView image I simply need to do something like:
int[] img_coordinates = new int[2];
ImageView image = (ImageView) findViewById(R.id.myImage);
image.getLocationOnScreen(img_coordinates);
And then I can actually compare these coordinates with the Touch-event's getRawX and getRawY.
If I want to get the center point of my view I just need to do this:
x_center = (double)img_coordinates[0] + image.getWidth()/2.0;
y_center = (double)img_coordinates[1] + image.getHeight()/2.0;
I hope this helps other people too, it took me a while to find this approach and I am actually not sure if it is the best approach but it does the trick for me.
I have a RelativeLayout with an ImageView and 8 TextView's in it. I want to position labels around this image dynamically. I thought the best approach would be to rotate the image at 45 degree intervals and place a label at each position, however the Image/RelativeLayout doesn't redraw (even if invalidate is called) until the next predetermind onDraw call, and all the TextViews get put in the message queue for positioning after that, so all the TextViews get positioned ontop of each other at the 315 degree mark.
I tried posting a Runnable to the RelativeLayout in a hope it would be added to the message queue after the onDraw call but unfortunately it didn't work and I'm running out of ideas.
My current code is bellow to give an idea of what I'm trying to do:
public void setupMenuText() {
final float scale = getResources().getDisplayMetrics().density;
setupMenuItemText((TextView)findViewById(R.id.menu_text_pos0), (72*scale)+0.5f);
setupMenuItemText((TextView)findViewById(R.id.menu_text_pos1), (72*scale)+0.5f);
setupMenuItemText((TextView)findViewById(R.id.menu_text_pos2), (72*scale)+0.5f);
setupMenuItemText((TextView)findViewById(R.id.menu_text_pos3), (72*scale)+0.5f);
setupMenuItemText((TextView)findViewById(R.id.menu_text_pos4), (72*scale)+0.5f);
setupMenuItemText((TextView)findViewById(R.id.menu_text_pos5), (72*scale)+0.5f);
setupMenuItemText((TextView)findViewById(R.id.menu_text_pos6), (72*scale)+0.5f);
setupMenuItemText((TextView)findViewById(R.id.menu_text_pos7), (72*scale)+0.5f);
}
public void setupMenuItemText(TextView pT, float pY) {
relativeLayout.setRotation(relativeLayout.getRotation()+45);
pT.setText("Some Text");
pT.setRotation(0);
pT.setGravity(Gravity.CENTER_HORIZONTAL);
pT.setX(0);
pT.setY(pY);
}
EDIT: Thanks to JSchools for the answer, wasn't exactly what I needed but pointed me in the right direction and info was accurate.
For anyone else with the same problem, centering the text inside the TextView wont cut it. I manually had to set the size of the TextView to much higher than its intended use so that it would accurately be positioned relative to the image.
You need to set the rotation of each individual TextView. You seem to be rotating the container multiple times, but since all the TextViews are inside the container, and they all have zero rotation relative to the container, they seem stacked. Don't rotate the container at all. You will also need to set the position of the TextViews so that they will be arranged in a circle. Simply rotating them will stick them on top of each other.
i have a grid view and i want to apply flip rotation animation on every child of grid view.
when user touch on a grid view element it perform flip rotation animation and change image.
and i use table layout to create grid of images.
i want to perform like thisPlz check once
this performs on one(layout).
but i want to perform on a 48 elements.
any help from someone....
plz give suggestion soon..
thanks in advance....
One of the most convincing 3D flip animation I've seen is done here https://code.google.com/p/android-3d-flip-view-transition.
A lot of the other tutorials and sample codes don't produce believable 3D flips. A simple rotation on the y-axis isn't what's done in iOS.
There is also a video here: http://youtu.be/52mXHqX9f3Y
So, to flip each grid element, simple call:
ViewFlipper viewFlipper = getViewFlipperForItem(i);
AnimationFactory.flipTransition(viewFlipper, FlipDirection.LEFT_RIGHT);
Where getViewFlipperForItem is a method you implement to get the ViewFlipper on that cell. I suggest you add each cell as a ViewFlipper (or ViewAnimator) and add the images you intend to flip within the ViewFlipper (or ViewAnimator). If this isn't clear to you, let me know.
Use the below code for adding flip animation to a view in android.
final ObjectAnimator animation = ObjectAnimator.ofFloat(view, "rotationY", 0.0f, 360f);
animation.setDuration(3000);
animation.setRepeatCount(ObjectAnimator.INFINITE);
animation.setInterpolator(new AccelerateDecelerateInterpolator());
animation.start();
view.startAnimation(animation);
Thanks Ephraim,
I used view flipper in my project and used that library that you have mentioned. It looks great and it help me out. Please any one who want to animate his view like rotate should use this library.
https://code.google.com/p/android-3d-flip-view-transition.