0

I want to set my my text under the center of my view. I know that I need to do it with Gravity but still dont see the right result I just wanted to do Animation that starts from under the center and go left right and return to started position My code is

        setContentView(R.layout.logo);
        mTextView = (TextView) findViewById(R.id.textLabel);
    mLayout = new LinearLayout(this); 
        mLayout.setGravity(Gravity.CENTER); 
        mTextView.setGravity(Gravity.AXIS_X_SHIFT/2); 
        mTextView.setGravity(Gravity.AXIS_Y_SHIFT/2-Gravity.AXIS_Y_SHIFT/3); 
        mAnimation = new TranslateAnimation(100f, -100f, 0.0f, 0.0f); 
        mAnimation.setDuration(2000); 
        mTextView.setAnimation(mAnimation);

        mAnimation.start();

and the xml looks like:

 <ViewFlipper android:id="@+id/flipper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:flipInterval="2000"
        android:layout_marginBottom="20dip" >
<LinearLayout
android:id="@+id/Linear"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/logonews"
android:baselineAligned="false"
android:orientation="horizontal" >

<TextView
    android:id="@+id/textLabel"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:singleLine="true"
    android:text="Israel News"
    android:textSize="18sp"
    android:textStyle="bold"

     />

  </LinearLayout>
  </ViewFlipper>

thanks for help

Vitaly Menchikovsky
  • 7,684
  • 17
  • 57
  • 89

2 Answers2

1

When do you want the Animation to play?

What result are you seeing instead?

If you want it to play immediately, use startAnimation instead of setAnimation.

Edit: Looking at your code in light of the comments you made...

If you want your TextView to be below your logo image, you'll need to remove the background drawable from the LinearLayout, change its orientation to vertical, and put the image into an ImageView instead, before your TextView in the LinearLayout. This allows Android to lay them out in order...

Like this:

 <ViewFlipper android:id="@+id/flipper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:flipInterval="2000"
        android:layout_marginBottom="20dip" >
<LinearLayout
android:id="@+id/Linear"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:baselineAligned="false"
android:orientation="vertical" >

<ImageView
    android:src="@drawable/logonews"
    android:scaleType="fitCenter"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
>


<TextView
    android:id="@+id/textLabel"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:singleLine="true"
    android:text="Israel News"
    android:textSize="18sp"
    android:textStyle="bold"

     />

  </LinearLayout>
  </ViewFlipper>

or if you need the image to be the background you can create an empty View above the TextView that's the same size as the image.

Jon O
  • 6,532
  • 1
  • 46
  • 57
  • the animation is working but not as I want it. I have a logo that is my background and is on the center of screen. and I want that my text view will be under the logo,like to set some position to start the animation place of text view – Vitaly Menchikovsky Apr 13 '12 at 14:46
  • You can use an animation resource to chain animations together using ``. See here: http://developer.android.com/guide/topics/resources/animation-resource.html If I understand you correctly, you can chain multiple translations together for the effect you want. – Jon O Apr 13 '12 at 14:58
  • why when I use mTextView.setGravity(Gravity.AXIS_Y_SHIFT/2-Gravity.AXIS_Y_SHIFT/3); its on the bottom of the view even the animation is canceled – Vitaly Menchikovsky Apr 13 '12 at 15:02
0
  • 1st, Gravity attribute has effects on the postion of text content in TextView, not the TextView.
  • 2nd, TranslateAnimation moves straightly only once. it will not move back and forward, so you may need combine several TranslateAnimation to implements what you want.
  • 3rd, user startAnimation.
Longerian
  • 723
  • 5
  • 13