give animation effect when click button on galleryview android - android

When I use Gallery widget, how do I get animate when I click a button to move from one picture to another??
Here is my screenshot of my gallery
When I swipe I got an animation like bounce effect, but when I click the prev and the next button, the picture just change without any animation.
Is there any way to attach some animation like slide efefct or something???
and here is my code
bnext.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if (selectedImagePosition < Imgid.length - 1) {
++selectedImagePosition;
}
gallery.setSelection(selectedImagePosition, false);
gallery.startAnimation(grow);
}
});
bprev.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if (selectedImagePosition > 0) {
--selectedImagePosition;
}
gallery.setSelection(selectedImagePosition, false);
}
});
Thanks

Related

Android Animation not work when i call visibility

The animation does not work after I set visibility to Invisible, I tried clear animation but not work. I have a button when I click the button it opens a linear layout with animation when I press back button I set the linear layout visibility to invisible again I click the button linear layout appear but no animation please help me.
l1 = (LinearLayout) findViewById(R.id.lnrlgn);
l2 = (LinearLayout) findViewById(R.id.lnrlgn1);
l2.setVisibility(View.INVISIBLE);
Animation uptodown = AnimationUtils.loadAnimation(this,R.anim.uptodown);
viewcrrd.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
l2.setAnimation(downtoup);
l2.clearanimation(); // is it right ?
l2.setVisibility(View.VISIBLE);
}
});
public void onBackPressed() {
// super.onBackPressed();
if (back_pressed + TIME_DELAY > System.currentTimeMillis()) {
// super.onBackPressed();
Exitdlg alert = new Exitdlg();
alert.showDialog(LoginActivity.this, "Are You Sure ");
l2.clearAnimation();
} else {
l2.clearAnimation();
l2.setVisibility(View.INVISIBLE);
}
back_pressed = System.currentTimeMillis();
}
Use startAnimation instead of setAnimation
viewcrrd.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
l2.setVisibility(View.VISIBLE);
l2.clearanimation();
l2.startAnimation(downtoup);
}
});

How to handle touch event on a ImageView

I have three Images. When I first touch, first Image is shown, when I second touch, second Image is shown, and then when I third touch, third Image is shown. After all, when I fourth touch, I want to show first Image return and so on.
Can someone point me to show how handling or touching on a ImageView of android?
The below should do what you need:
public class MainActivity extends Activity {
ImageView image;
int i=1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
image = (ImageView) findViewById(R.id.imageViewName);
setButtonOnClickListeners();
}
}
image.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (i==1){
image.setImageResource(R.drawable.image1);
i++;
}
else if(i==2){
image.setImageResource(R.drawable.image2);
i++;
}
else if(i==3){
image.setImageResource(R.drawable.image3);
i++;
}
else if(i==4){
image.setImageResource(R.drawable.image4);
i=1;
}
}
});
I've not tested but the idea is correct. When you click the image it will change the drawable depending on the value of i. When you get image 1 i will equal 1. Onclick will increment i until i==4 which it will reset to 1 as you requested.
A while loop might be tidier but this was the quickest soultion I thought of.
how to handle click on an ImageView
You can simply set a View.OnClickListener for your ImageView:
imageView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// do stuff
}
});

How can I make previous item's button visible when click on current item's button in recyclerview?

What I want is when I click the "x" button of the second item, it will remove the second item and then make the "+" of the first item visible. Here is what I try but not work, the "+" button is not showed.
holder.ivDelete.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
View view = recyclerView.getChildAt(position - 1);
holder.ivAdd = (ImageView) view.findViewById(R.id.img_add_items);
holder.ivAdd.setVisibility(View.VISIBLE);
list.remove(position);
notifyDataSetChanged();
}
});
Try this code,
holder.ivDelete.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
View view = recyclerView.getChildItemId(position - 1);
holder.ivAdd = (ImageView) view.findViewById(R.id.img_add_items);
holder.ivAdd.setVisibility(View.VISIBLE);
list.remove(position);
notifyDataSetChanged();
}
});
I hope that will help you for solving your problem.

How can I optimize the performance of opening an Android fragment?

I have created an 800 xml layout and a Fragment class, but opening a fragment with a button click takes too long.
Can anyone help me optimize the following code sample?
View lesson655 = (View) getActivity().findViewById(R.id.txtlesson655);
lesson655.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
int i;
pager.setCurrentItem(0);
for (i = 1; i <= 655; i++) {
pager.setCurrentItem(pager.getCurrentItem() + 1);
}
}
});
If you don't need to go step by step through every Item you can do it this way:
View lesson655 = (View) getActivity().findViewById(R.id.txtlesson655);
lesson655.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
pager.setCurrentItem(655);
}
});

first click change to new image and second click change to old image, android

this application requires:
first click will change image1 to image2
second click will change back to old image (image2 to image1)
image1 = (ImageView)findViewById(R.id.imageView1);
image1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
image1.setImageResource(R.drawable.a3_01);
image1.setTag(70);
}
});
this image will set a new tag for the server knows that the picture have been change.
*the code i used is only for the first click and it works. ive just have no idea to make a second click event. can anyone gives me idea of it? much appreciate. thanks.
You could use a boolean to act as a switch for you to flop back and forth with an if statement.
boolean showingFirst = true;
image1 = (ImageView)findViewById(R.id.imageView1);
image1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if(showingFirst == true){
image1.setImageResource(R.drawable.a3_02);
showingFirst = false;
}else{
image1.setImageResource(R.drawable.a3_01);
image1.setTag(70);
showingFirst = true;
}
}
});
Put both images into an ImageSwitcher and use the Button clicks to call its showNext() method.
You can use if case in it like
public void onClick(View v) {
if (i == 0) {
Toast.makeText(getApplicationContext(), "First Click", 1000).show();
i++;
} else if (i == 1) {
Toast.makeText(getApplicationContext(), "Second Click", 1000).show();
i = 0;
}
}

Categories

Resources