如何在某个角度倾斜一个子布局 [英] How to tilt a child layout at some angle
问题描述
我试过了自定义视图和倾斜的形象成功45度,但我想倾斜一定角度,整个儿layoout所以,无论我会在子布局的添加将automactically平铺..仅供参考,请取看看附加的图片
连我都试过这code,但它不会帮助
公共类CustomLinear扩展的LinearLayout {
私人矩阵mForward =新的Matrix();
私人矩阵mReverse =新的Matrix();
私人浮动[] = mTemp新的浮动[2];公共CustomLinear(上下文的背景下){
超级(上下文);
}公共CustomLinear(上下文的背景下,ATTRS的AttributeSet){
超(背景下,ATTRS);
}@覆盖
保护无效dispatchDraw(帆布油画){canvas.rotate(75,的getWidth()/ 2,的getHeight()/ 2);mForward = canvas.getMatrix();
mForward.invert(mReverse);
canvas.save();
canvas.setMatrix(mForward); //这是我们需要使用的矩阵
//触摸事件的适当定位
super.dispatchDraw(画布);
canvas.restore();
无效();
}@覆盖
公共布尔dispatchTouchEvent(MotionEvent事件){
event.setLocation(的getWidth() - event.getX(),的getHeight() - event.getY());
返回super.dispatchTouchEvent(事件);
}}
我的事情有可能使用的旋转动画。你可以用 0时长在On_create孩子整个童年布局应用动画。
下面是动画code
<?XML版本=1.0编码=UTF-8&GT?;
<旋转
的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:fromDegrees =0
机器人:toDegrees = - 90
机器人:pivotX =50%
机器人:pivotY =50%
机器人:时间=0
机器人:fillAfter =真正的>
< /旋转>
您可以设置旋转角度根据自己的需要。
然后使用给定的code在活动的onCreate,
@覆盖
公共无效的onCreate(包B){
super.onCreate(二);
的setContentView(R.layout.myscreen);
动画rotate_anim = AnimationUtils.loadAnimation(这一点,R.anim.rotation);
LayoutAnimationController anim_controller =新LayoutAnimationController(rotate_anim,0);
的FrameLayout布局=(的FrameLayout)findViewById(R.id.MyScreen_ContentLayout);
layout.setLayoutAnimation(anim_controller);
}
I've tried the custom view and tilt the image to 45 degree successfully but I want to tilt the whole child layoout at some angle so that whatever I'll add in that child layout will automactically tiled .. For reference please take a look at the attached picture
even I have tried this code but it wont help
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);
}
}
I thing it is possible using rotate animation. you can apply animation on the whole child layout with 0 duration in On_create.
Here is the animation code
<?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>
You can set the rotation angle as per your need.
Then use given code in your Activity's 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);
}
这篇关于如何在某个角度倾斜一个子布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!