这是我的createoverlap()函数:-
当前,我正面临一个问题,因为它在单击特定视图时正确重叠。但如果当时已选择视图,则不会重叠。 它显示更大的尺寸,并且只有动画添加到该圆圈中。
private void CreateOverLap(final int number, int lastposition) {
for (int i = 0; i < number; i++) {
final CircleImageView img = new CircleImageView(this);
final ImageView imgAnim = new ImageView(this);
final TextView text = new TextView(this);
final FrameLayout frame = new FrameLayout(this);
frame.setId(i);
final int padding = getResources().getDimensionPixelSize(R.dimen.xxxx_large_space25);
int imgSize = getResources().getDimensionPixelSize(R.dimen.anim_img);
int imgAnimSize = getResources().getDimensionPixelSize(R.dimen.scrollpop);
FrameLayout.LayoutParams pa = new FrameLayout.LayoutParams(imgAnimSize, imgAnimSize);
final FrameLayout.LayoutParams paImg = new FrameLayout.LayoutParams(imgSize, imgSize);
final FrameLayout.LayoutParams paTxt = new FrameLayout.LayoutParams(imgSize, imgSize);
final FrameLayout.LayoutParams paTxtAfter = new FrameLayout.LayoutParams(imgAnimSize, imgAnimSize);
final FrameLayout.LayoutParams paImgAfter = new FrameLayout.LayoutParams(imgAnimSize, imgAnimSize);
FrameLayout.LayoutParams paImgAnim = new FrameLayout.LayoutParams(imgAnimSize, imgAnimSize);
final CircularProgressDrawable drawable = new CircularProgressDrawable.Builder()
.setRingWidth(getResources().getDimensionPixelSize(R.dimen.drawable_ring_size))
.setOutlineColor(getColor(this, android.R.color.transparent))
.setRingColor(getColor(this, R.color.colorAppGreen))
.setCenterColor(getColor(this, android.R.color.transparent))
.setInnerCircleScale(0.98f)
.create();
imgAnim.setImageDrawable(drawable);
img.setImageResource(R.mipmap.ic_launcher);
paImg.gravity = Gravity.CENTER;
paTxt.gravity = Gravity.CENTER;
paTxtAfter.gravity = Gravity.CENTER;
int margin = getResources().getDimensionPixelSize(R.dimen.marginscroll);
pa.setMargins(margin * i, 0, 0, 0);
frame.setLayoutParams(pa);
img.setLayoutParams(paImg);
img.setPadding(23, 23, 23, 23);
imgAnim.setLayoutParams(paImgAnim);
text.setLayoutParams(paTxt);
text.setText("" + i);
text.setTextColor(Color.WHITE);
text.setTextSize(20f);
text.setShadowLayer(25, 5, 5, Color.BLACK);
text.setGravity(Gravity.CENTER);
//frame.setTag(""+i);
frame.addView(imgAnim);
frame.addView(img);
frame.addView(text);
frame.setTag("deselected" + i);
img.setTag(drawable);
final int finalI = i;
Log.d("frame_tag:-", "" + frame.getTag().toString());
CircleImageView cirImg = null;
TextView textView = null;
FrameLayout frLay = null;
if (prevFramep == null) {
if (frame.getTag().equals("deselected" + lastposition)) {
frLay = frame;
Animator currentAnimation = preparePulseAnimation(drawable);
currentAnimation.start();
currentAnimation = prepareStyle2Animation(drawable, false);
currentAnimation.start();
frLay.setTag("selected");
prevFramep = frLay;
Log.d("frlay_child_count", "" + prevFramep.getChildCount());
/*for (int j = 1; j < prevFramep.getId();j++){
Log.d("frlay-id",""+prevFramep.getId());
int res = j;
flScroll.bringChildToFront(flScroll.findViewById(res));
}
for (int k = number-1; k > prevFramep.getId();k--){
Log.d("frlay-id",""+prevFramep.getId());
flScroll.bringChildToFront(flScroll.findViewById(k-1));
}*/
for (int i1 = 0; i1 < prevFramep.getChildCount(); i1++) {
if (prevFramep.getChildAt(i1) instanceof CircleImageView) {
cirImg = (CircleImageView) prevFramep.getChildAt(i1);
}
}
if (cirImg != null) {
cirImg.setLayoutParams(paImgAfter);
}
for (int i2 = 0; i2 < prevFramep.getChildCount(); i2++) {
if (prevFramep.getChildAt(i2) instanceof TextView) {
textView = (TextView) prevFramep.getChildAt(i2);
}
}
if (textView != null) {
textView.setLayoutParams(paTxtAfter);
}
}else {
}
flScroll.bringChildToFront(frLay);
}
frame.setOnClickListener(new View.OnClickListener() {
@SuppressLint("ResourceType")
@Override
public void onClick(View v) {
FrameLayout frLay = (FrameLayout) v;
CircleImageView cirImg = null;
TextView textView = null;
Log.d("position", "" + finalI);
// profile_position=finalI;
//new setProfileLongOperation().execute("https://5fms1hdbp2.execute-api.eu-central-1.amazonaws.com/Test/setprofile");
if (prevFramep == null) {
Log.d("prevFramep", "null");
if (frLay.getTag().toString().contains("deselected")) {
Animator currentAnimation = preparePulseAnimation(drawable);
currentAnimation.start();
currentAnimation = prepareStyle2Animation(drawable, false);
currentAnimation.start();
frLay.setTag("selected");
prevFramep = frLay;
}
for (int i = 0; i < frLay.getChildCount(); i++) {
if (frLay.getChildAt(i) instanceof CircleImageView) {
cirImg = (CircleImageView) frLay.getChildAt(i);
}
}
if (cirImg != null) {
cirImg.setLayoutParams(paImgAfter);
}
for (int i = 0; i < frLay.getChildCount(); i++) {
if (frLay.getChildAt(i) instanceof TextView) {
textView = (TextView) frLay.getChildAt(i);
}
}
if (textView != null) {
textView.setLayoutParams(paTxtAfter);
}
} else {
Log.d("prevFramep", "not null");
if (prevFramep.getTag().toString().contains("selected")) {
Log.d("prevFramep", "selected");
if (prevFramep.getId() != frLay.getId()) {
Log.d("prevFramep", "not=to frlay");
for (int j = 0; j < prevFramep.getChildCount(); j++) {
if (prevFramep.getChildAt(j) instanceof CircleImageView) {
cirImg = (CircleImageView) prevFramep.getChildAt(j);
break;
}
}
if (cirImg != null) {
CircularProgressDrawable dr = (CircularProgressDrawable) cirImg.getTag();
if (dr != null) {
Animator currentAnimation1 = preparePulseAnimation(dr);
currentAnimation1.start();
currentAnimation1 = prepareStyle2Animation(dr, true);
currentAnimation1.start();
Animator currentAnimation = preparePulseAnimation(drawable);
currentAnimation.start();
currentAnimation = prepareStyle2Animation(drawable, false);
currentAnimation.start();
frLay.setTag("selected");
prevFramep = frLay;
}
/*Previously selected circularImage View*/
if (cirImg != null) {
cirImg.setLayoutParams(paImg);
}
/*Currently selected CircularImageview*/
for (int i = 0; i < frLay.getChildCount(); i++) {
if (frLay.getChildAt(i) instanceof CircleImageView) {
cirImg = (CircleImageView) frLay.getChildAt(i);
}
}
if (cirImg != null) {
cirImg.setLayoutParams(paImgAfter);
}
/*Previously selected textview*/
for (int i = 0; i < prevFramep.getChildCount(); i++) {
if (prevFramep.getChildAt(i) instanceof TextView) {
textView = (TextView) prevFramep.getChildAt(i);
}
}
if (textView != null) {
textView.setLayoutParams(paTxt);
}
/*currently selected TextView*/
for (int i = 0; i < frLay.getChildCount(); i++) {
if (frLay.getChildAt(i) instanceof TextView) {
textView = (TextView) frLay.getChildAt(i);
}
}
if (textView != null) {
textView.setLayoutParams(paImgAfter);
}
}
} else {
Log.d("prevFramep", "=to frlay");
prevFramep = frLay;
}
}
if (frLay.getTag().toString().contains("deselected")) {
Log.d("frlay", "deselected");
Animator currentAnimation = preparePulseAnimation(drawable);
currentAnimation.start();
currentAnimation = prepareStyle2Animation(drawable, false);
currentAnimation.start();
frLay.setTag("selected");
prevFramep = frLay;
}
}
Log.d("frlay_child_count", "" + frLay.getChildCount());
for (int j = 1; j < frLay.getId(); j++) {
Log.d("frlay-id", "" + frLay.getId());
int res = j;
flScroll.bringChildToFront(flScroll.findViewById(res));
}
for (int k = number - 1; k > frLay.getId(); k--) {
Log.d("frlay-id", "" + frLay.getId());
flScroll.bringChildToFront(flScroll.findViewById(k));
}
flScroll.bringChildToFront(frLay);
}
});
flScroll.addView(frame, i);
}
}
布局代码:-
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<HorizontalScrollView
android:id="@+id/topHsv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:scrollbars="none">
<FrameLayout
android:id="@+id/flScroll"
android:layout_width="wrap_content"
android:clipChildren="false"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical">
</FrameLayout>
</HorizontalScrollView>
</android.support.constraint.ConstraintLayout>
我也在尝试各种方法来修复它,但没有任何解决方法。