我试过自定义视图,并成功地将图像倾斜到45度,但我想将整个子布局倾斜到某个角度,以便在该子布局中添加的任何内容都将自动平铺。请看所附图片以供参考
就连我也试过这个密码但没用

public class CustomLinear extends LinearLayout{
private Matrix mForward = new Matrix();
private Matrix mReverse = new Matrix();
private float[] mTemp = new float[2];

public CustomLinear(Context context) {
super(context);
}

public CustomLinear(Context context, AttributeSet attrs) {
super(context, attrs);
}

@Override
protected void dispatchDraw(Canvas canvas) {

canvas.rotate(75, getWidth() / 2, getHeight() / 2);

mForward = canvas.getMatrix();
mForward.invert(mReverse);
canvas.save();
canvas.setMatrix(mForward); // This is the matrix we need to use for
                                        // proper positioning of touch events
super.dispatchDraw(canvas);
canvas.restore();
invalidate();
}

@Override
public boolean dispatchTouchEvent(MotionEvent event) {
event.setLocation(getWidth() - event.getX(), getHeight() - event.getY());
return super.dispatchTouchEvent(event);
}

}

最佳答案

我认为使用旋转动画是可能的。您可以在“创建时”中对整个子布局应用0持续时间的动画。
这是动画代码

<?xml version="1.0" encoding="utf-8"?>
    <rotate
     xmlns:android="http://schemas.android.com/apk/res/android"
        android:fromDegrees="0"
        android:toDegrees="-90"
        android:pivotX="50%"
        android:pivotY="50%"
        android:duration="0"
        android:fillAfter="true">
    </rotate>

您可以根据需要设置旋转角度。
然后在活动的oncreate中使用给定的代码,
  @Override
  public void onCreate(Bundle b) {
  super.onCreate(b);
     setContentView(R.layout.myscreen);
     Animation rotate_anim = AnimationUtils.loadAnimation(this, R.anim.rotation);
     LayoutAnimationController anim_controller = new LayoutAnimationController(rotate_anim, 0);
     FrameLayout layout = (FrameLayout)findViewById(R.id.MyScreen_ContentLayout);
     layout.setLayoutAnimation(anim_controller);
 }

10-08 20:24