简体   繁体   中英

Rotating a RelativeLayout in Android 2.3

I am new to android and would like some assistance on rotating my relative layout for a two-player game I am working on. I have seen the posts here and have looked into many other posts on the same subject on SO. My first question is how to I call the new class I just made? For all the posts that dont just tell me to use android:rotation (which is not avaliable in 2.3-) I make a new class, but I get a notification that the class is never called. Do I call the class simmilar to how I call a method? Or is there some command in AndroidManifest? Finialy, how does the new class rotate only one Relative layout and not the other? I just would like to know how its supposted to work.
This is the new Class that I am supposted to make:

public class MyRelativeLayout extends RelativeLayout {    
public MyRelativeLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    init();
}

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

public MyRelativeLayout(Context context) {
    super(context);
    init();
}

private void init() {
    setStaticTransformationsEnabled(true);
}

@Override
protected boolean getChildStaticTransformation(View child, Transformation t) {
    t.setTransformationType(Transformation.TYPE_MATRIX);
    Matrix m = t.getMatrix();
    m.reset();
    m.postRotate(180, child.getWidth() / 2.0f, child.getHeight() / 2.0f);
    return true;

Thanks for your help

在活动的oncreate()方法中,执行setContentView(new MyRelativeLayout(this))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM