3

I have an Activity in Landscape-Mode. Inside there is a Custom-Title-View aligned like this:

Current View

Is it possible to keep the landscape mode and 'fake' this one View into portrait-mode like this: desired View

I have tried to overwrite my custom TitleView and put something like this to draw(Canvas)

 public class VerticalTitle extends Title{

      public draw(Canvas){
           canvas.save();
           canvas.rotate(getWidth() / 2, getHeight() / 2);
           // i tryed many translations, but get none to work
           canvas.translate(0, getHeight());
           super.draw(canvas);
           canvas.restore()
      }

      public void onMeasure(int widthMeasureSpec, int heightMeasureSpec){
           super.onMeasure(heightMeasureSpec, widthMeasureSpec);
           setMeasuredDimension(getMeasuredHeight(), getMeasuredWidth());
      }
}

If it is on any interest, The TitleBar extends from RelativeLayout and has fixed height and fill_parent width

The setRotate parameter from View is not an option, because the app should stay compatible to 2.2.

Rafael T
  • 15,401
  • 15
  • 83
  • 144

2 Answers2

1

I have never done this but I found two other answers here on SO that show ways you might accomplish this.

The first one involves extending the TextView class, and is here. Since you want to do a whole view though, I think the next answer is better suited to your situation.

The other answer is to create an animation using rotation to deal with it. That answer is here.

Community
  • 1
  • 1
Barak
  • 16,318
  • 9
  • 52
  • 84
1

you have to extend Text view And build your custom vertical TextView first see these two links for more details

  1. Vertical TextView
  2. Vertical rotated label

and after that in your Layout-land you can use this Xml file for your layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <com.yourpackage.CustomVerticalTextView
        android:layout_width="42dp"
        android:layout_height="fill_parent"
        android:text="@string/hello"
        android:background="#0000FF" />

</LinearLayout>

If you want to rotate the layout instead of rotating all of its children by 90 degrees use LayoutAnimationController

see this SO thread for more details

Community
  • 1
  • 1
K_Anas
  • 31,226
  • 9
  • 68
  • 81
  • It doesn't really, as the questioner want to rotate anything but the cameraPreview. I just want to rotate/transform the Custom View, and let the rest untouched – Rafael T May 30 '12 at 14:03
  • what's your custom view isn't the vertical text view? – K_Anas May 30 '12 at 18:16
  • finally it works with a merge of your Links. The problem was the fixed Size inside XML. I could render it without any problem to a FrameLayout of width and height= FILL_PARENT – Rafael T Jun 04 '12 at 14:50