2

Hy!

I've created a button on android in which the text looks like this: http://i51.tinypic.com/2u4oaww.png It looks like this because the activity is in landscape mode.What I want next is to rotate the text on the button for it to look normally, but I can figure out how this could be done.

I tried with animation, like this:

In res/anim/myanim.xml:

<rotate  xmlns:android="http://schemas.android.com/apk/res/android"
           android:fromDegrees="0" 
           android:toDegrees="180"
           android:pivotX="50%"
           android:duration="0" />

 takePhoto = (Button) findViewById(R.id.btnPhoto);
        takePhoto.setText(t);
        RotateAnimation ranim = (RotateAnimation)AnimationUtils.loadAnimation(this, R.anim.myanim);
          ranim.setFillAfter(true);
        takePhoto.setAnimation(ranim);

But when I do this my button won't appear on the screen no more! Could someone tell me how could I fix that?Thanks

EDIT:

<?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="horizontal">
    <LinearLayout android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:orientation="vertical"
    android:layout_weight="1.0">
      <SurfaceView  
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
   android:id="@+id/surface_camera"
    />

    </LinearLayout>
    <LinearLayout android:layout_width="90dip"
    android:layout_height="fill_parent">
        <Button 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:id="@+id/btnPhoto"
    android:text="Take Photo"
    android:layout_gravity="bottom|left" 
/>
    </LinearLayout>
</LinearLayout>
adrian
  • 4,574
  • 17
  • 68
  • 119
  • Here is good example by extends TextView: http://stackoverflow.com/questions/1258275/vertical-rotated-label-in-android/2599518#2599518 – NguyenDat Aug 05 '11 at 07:46
  • 1
    Try out this Link May be helpful... http://stackoverflow.com/questions/2888780/is-it-possible-to-write-vertically-in-a-textview-in-android – Uttam Aug 05 '11 at 07:50
  • 1
    @Uttam that was exactly what I tried.If u look close enough you'll see that is the same code! – adrian Aug 05 '11 at 07:52

1 Answers1

5

This should fix the problem.

<?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" />

First of all it seems you want to rotate it 90 ccw instead of 180. Also if you set the duration to something significant like 4 seconds, you'll see that in your code the button will pivot outside the container becoming invisible, that's why you'll have to pivot in the center of the button.

Joost
  • 1,426
  • 2
  • 16
  • 39
  • Is good.Here is how it looks http://i51.tinypic.com/2h2iepz.png .But I cannot make it look any large. – adrian Aug 05 '11 at 08:12
  • I'm not sure if it can be streched with XML, I recommend you just modify the width of the button based on the screen dimensions in code. Get the screen dimensions: http://stackoverflow.com/questions/1016896/android-how-to-get-screen-dimensions I assume you'll be able to figure that out. – Joost Aug 05 '11 at 08:28
  • And how can I set the dimensions of the button? – adrian Aug 05 '11 at 08:34
  • How about buttonObject.setWidth(int); and buttonObject.setHeight(int); where int should be the number of pixels. http://developer.android.com/reference/android/widget/TextView.html#attr_android:width – Joost Aug 05 '11 at 08:38
  • Sorry my bad you should be using LayoutParams to modify width programmatically. – Joost Aug 05 '11 at 09:27
  • @JoostvanDoorn let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/2147/discussion-between-george-and-joost-van-doorn) – adrian Aug 05 '11 at 09:37