arg*_*eus 7 java android relativelayout
我正在尝试制作一个应用程序,它适用于两个人并且都看到它的一半,所以我需要垂直翻转一半.我在里面使用了LinearLayout两个RelativeLayouts layout_weight="1".
事情是,我不知道如何做这个翻转.显然android:rotate只能在版本11+(3.0+)中使用,但我希望它至少支持2.2.
在阅读了关于SO的其他相关问题后,我尝试了各种各样的东西,但似乎都没有.我试图扩展RelativeLayout并覆盖该onDraw函数,但它似乎没有做任何事情.这是我的代码:
public class FlippedRelativeLayout extends RelativeLayout
{
public FlippedRelativeLayout(Context context)
{
super(context);
}
public FlippedRelativeLayout(Context context, AttributeSet attrs)
{
super(context, attrs);
}
public FlippedRelativeLayout(Context context, AttributeSet attrs,
int defStyle)
{
super(context, attrs, defStyle);
}
@Override
protected void onDraw(Canvas canvas)
{
canvas.save();
canvas.rotate(180);
super.onDraw(canvas);
canvas.restore();
}
}
Run Code Online (Sandbox Code Playgroud)
我会很高兴得到任何帮助,谢谢!
试试这个:
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;
}
}
Run Code Online (Sandbox Code Playgroud)
结果是:

| 归档时间: |
|
| 查看次数: |
2117 次 |
| 最近记录: |