但问题是,如果我点击一个图像,则会在该特定图像上绘制单行,并且每个其他viewpager项目都不会在点击时绘制
点击任何图片后我想要两行,所以该怎么做
ivImageOne.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
id = arraylist.get(position).get("user_id1");
feed_id = arraylist.get(position).get("feed_id");
Log.e("feeeeeee", feed_id);
View tempView = (View) v.getTag(R.integer.btnminusview);
Integer pos = (Integer) v.getTag(R.integer.btnminuspos);
ivRightTick = (ImageView) tempView.findViewById(R.id.ivRightTick);
ivLeftTick = (ImageView) tempView.findViewById(R.id.ivLeftTick);
ivLeftTick.setVisibility(View.GONE);
ivRightTick.setVisibility(View.VISIBLE);
vOne = (View) tempView.findViewById(R.id.vOne);
vTwo = (View) tempView.findViewById(R.id.vTwo);
mThread = new Thread() {
@Override
public void run() {
while (pStatus < pcount1) {
pStatus += 10;
handler.post(new Runnable() {
@Override
public void run() {
android.view.ViewGroup.LayoutParams params = vOne.getLayoutParams();
params.height = pStatus;
params.width = 10;
Log.d("pppppppppppppp", params.height + "");
vOne.setLayoutParams(params);
// vOne.setLayoutParams(new WindowManager.LayoutParams(1,pStatus));
if (pStatus == pcount1) {
stopThread(mThread);
}
}
});
try {
Thread.sleep(19); //thread will take approx 2.5 seconds to finish
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
};
mThread2 = new Thread() {
@Override
public void run() {
while (pStatus2 > MIN_VALUE) {
pStatus2 += 10;
handler2.post(new Runnable() {
@Override
public void run() {
android.view.ViewGroup.LayoutParams params = vTwo.getLayoutParams();
params.height = pStatus;
params.width = 10;
Log.d("pppppppppppppp", params.height + "");
vTwo.setLayoutParams(params);
// vOne.setLayoutParams(new WindowManager.LayoutParams(1,pStatus));
if (pStatus2 == pcount2) {
stopThread(mThread2);
}
}
});
try {
Thread.sleep(19); //thread will take approx 2.5 seconds to finish
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
};
mThread.start();
mThread2.start();
}
});
ivFeedImageTwo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// giveVote(2);
id = arraylist.get(position).get("user_id2");
feed_id = arraylist.get(position).get("feed_id");
View tempView = (View) v.getTag(R.integer.btnminusview);
Integer pos = (Integer) v.getTag(R.integer.btnminuspos);
ivLeftTick = (ImageView) tempView.findViewById(R.id.ivLeftTick);
ivRightTick = (ImageView) tempView.findViewById(R.id.ivRightTick);
ivLeftTick.setVisibility(View.VISIBLE);
ivRightTick.setVisibility(View.GONE);
vOne = (View) tempView.findViewById(R.id.vOne);
vTwo = (View) tempView.findViewById(R.id.vTwo);
mThread = new Thread() {
@Override
public void run() {
while (pStatus < pcount2) {
pStatus += 10;
handler.post(new Runnable() {
@Override
public void run() {
android.view.ViewGroup.LayoutParams params = vTwo.getLayoutParams();
params.height = pStatus;
params.width = 10;
Log.d("pppppppppppppp", params.height + "");
vTwo.setLayoutParams(params);
// vOne.setLayoutParams(new WindowManager.LayoutParams(1,pStatus));
if (pStatus == pcount2) {
stopThread(mThread);
}
}
});
try {
Thread.sleep(19); //thread will take approx 2.5 seconds to finish
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
};
mThread2 = new Thread() {
@Override
public void run() {
while (pStatus2 > MIN_VALUE) {
pStatus2 += 10;
handler2.post(new Runnable() {
@Override
public void run() {
android.view.ViewGroup.LayoutParams params = vOne.getLayoutParams();
params.height = pStatus;
params.width = 10;
Log.d("pppppppppppppp", params.height + "");
vOne.setLayoutParams(params);
// vOne.setLayoutParams(new WindowManager.LayoutParams(1,pStatus));
if (pStatus2 == pcount1) {
stopThread(mThread2);
}
}
});
try {
Thread.sleep(19); //thread will take approx 2.5 seconds to finish
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
};
mThread2.start();
mThread.start();
}
});
答案 0 :(得分:0)
以下是您处理紧急问题的方法:
在您的活动/片段上编码一个方法,用于启动两行的动画。然后设置两个相同的OnClickListener
s,每个图像上一个,只需调用动画方法。
我更关心的是你使用Thread
来制作动画。这不是Android的方式。您应该使用动画师对视图进行视觉更改。代码可以简单如下:
float pct = ... // ratio of votes to total votes, from 0.0 to 1.0
vOne.setScaleX(0F);
vOne.animate().setDuration(150).scaleXBy(pct).start();
请查看Android开发者网站和网络其他地方的一些动画教程。