Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>extend Button class:</p> <pre><code>public class RotateButton extends Button{ public RotateButton(Context context) { super(context); } public RotateButton(Context context, AttributeSet attrs) { super(context, attrs); } @Override protected void onDraw(Canvas canvas) { canvas.save(); canvas.rotate(45, getWidth() / 2, getHeight() / 2); super.onDraw(canvas); canvas.restore(); } } </code></pre> <p>and in your layout:</p> <pre><code>&lt;com.samples.myapp.ui.RotateButton android:layout_height="wrap_content" android:id="@+id/MyBtn" android:padding="5dip" android:textColor="@color/darkGreen" android:textSize="16dip" android:text="TextView" android:layout_width="wrap_content"&gt;&lt;/com.samples.myapp.ui.RotateButton&gt; </code></pre> <p><strong>----------------------------------------------------------------------</strong></p> <p><strong>edit:</strong></p> <p>Another approach: design a rotatable LinearLayout and put your controls in it. LinearLayout can be rotated completely:</p> <pre><code>package org.mabna.order.ui; import android.content.Context; import android.graphics.Canvas; import android.graphics.Matrix; import android.util.AttributeSet; import android.view.MotionEvent; public class RotateLinearLayout extends LinearLayout{ private Matrix mForward = new Matrix(); private Matrix mReverse = new Matrix(); private float[] mTemp = new float[2]; public RotateLinearLayout(Context context) { super(context); } public RotateLinearLayout(Context context, AttributeSet attrs) { super(context, attrs); } @Override protected void dispatchDraw(Canvas canvas) { canvas.rotate(180, 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); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload