我有一个相对简单的回收站视图,用户可以选择图像。这些图像中的某些可能会旋转90、180、270度。我一直无法获得旋转的图像以正确显示,它们始终被裁剪。下图显示了一个简单图像的视图,该图像在其正常方向(横向)和旋转90度(纵向和剪切)时均如此。另外,附加了代码的相关部分。任何指针都非常感谢。
@Override
public void onBindViewHolder(@NonNull PickerViewHolder holder, int position) {
final ViewGroup parent = (ViewGroup) holder.itemView;
// clear out any existing children
parent.removeAllViews();
final ImageView view = new ImageView(ActivityJigsaw.this);
view.setScaleType(ImageView.ScaleType.CENTER);
view.setImageResource(R.drawable.whitebox);
view.setAdjustViewBounds(true);
if ((toggle & 1) == 0 ) view.setRotation(90f);
toggle ^= 1;
parent.addView(view, holder.viewLayoutParams);
}
class PickerViewHolder extends RecyclerView.ViewHolder {
private final FrameLayout.LayoutParams viewLayoutParams;
private final FrameLayout.LayoutParams shadowLayoutParams;
PickerViewHolder(final View itemView) {
super(itemView);
// generate layout parameters
viewLayoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.CENTER);
}
}