|
|
|
@ -1,6 +1,7 @@ |
|
|
|
|
package com.unionmed.unionmedtv.utils; |
|
|
|
|
|
|
|
|
|
import android.content.Context; |
|
|
|
|
import android.graphics.Canvas; |
|
|
|
|
import android.graphics.Rect; |
|
|
|
|
import android.view.View; |
|
|
|
|
|
|
|
|
@ -8,18 +9,19 @@ import androidx.annotation.NonNull; |
|
|
|
|
import androidx.recyclerview.widget.RecyclerView; |
|
|
|
|
|
|
|
|
|
import com.blankj.utilcode.util.SizeUtils; |
|
|
|
|
import com.unionmed.unionmedtv.widgets.ImgConstraintLayout; |
|
|
|
|
|
|
|
|
|
import org.jetbrains.annotations.NotNull; |
|
|
|
|
|
|
|
|
|
public class LinearSpacingItemDecoration extends RecyclerView.ItemDecoration { |
|
|
|
|
|
|
|
|
|
private int spacing;//间距padding
|
|
|
|
|
|
|
|
|
|
public LinearSpacingItemDecoration(Context context, int spacings) { |
|
|
|
|
//获取需要设置的间距值dp,这里不写死,调用时传过来
|
|
|
|
|
// spacing = context.getResources().getDimensionPixelSize(R.dimen.d10);
|
|
|
|
|
spacing = SizeUtils.dp2px(spacings); |
|
|
|
|
// spacing = spacings;
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) { |
|
|
|
|
super.getItemOffsets(outRect, view, parent, state); |
|
|
|
@ -29,4 +31,35 @@ public class LinearSpacingItemDecoration extends RecyclerView.ItemDecoration { |
|
|
|
|
outRect.bottom = spacing;//设置bottom padding
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void onDraw(@NonNull @NotNull Canvas c, @NonNull @NotNull RecyclerView parent, @NonNull @NotNull RecyclerView.State state) { |
|
|
|
|
super.onDraw(c, parent, state); |
|
|
|
|
for (int i = 0; i < parent.getChildCount(); i++) { |
|
|
|
|
View child = parent.getChildAt(i); |
|
|
|
|
if(child instanceof ImgConstraintLayout) { |
|
|
|
|
boolean isSelected = ((ImgConstraintLayout) child).isFocus(); |
|
|
|
|
if (isSelected) { |
|
|
|
|
// 计算缩放比例
|
|
|
|
|
float scale = 1.05f; |
|
|
|
|
// 设置缩放pivot点
|
|
|
|
|
child.setPivotX(child.getWidth() / 2); |
|
|
|
|
child.setPivotY(child.getHeight() / 2); |
|
|
|
|
|
|
|
|
|
// 进行缩放
|
|
|
|
|
child.setScaleX(scale); |
|
|
|
|
child.setScaleY(scale); |
|
|
|
|
}else { |
|
|
|
|
// 计算缩放比例
|
|
|
|
|
float scale = 1; |
|
|
|
|
// 设置缩放pivot点
|
|
|
|
|
child.setPivotX(child.getWidth() / 2); |
|
|
|
|
child.setPivotY(child.getHeight() / 2); |
|
|
|
|
|
|
|
|
|
// 进行缩放
|
|
|
|
|
child.setScaleX(scale); |
|
|
|
|
child.setScaleY(scale); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|