2012-02-07 3 views
1

2つの同一のTextViewを配置したFrameLayoutがあります。 私は最初のビューを左に翻訳したいと思っています(これは私が行っており、魅力のように働いています)。しかし、私はその下にあるTextViewをクリックしてアクションを実行できるようにしたいと考えています。Android:FrameLayout内のアニメーションを翻訳した後、下部のTextViewをクリックできません

下部のTextViewをクリックしようとすると、上部のTextViewが代わりにクリックされます。アニメーションがレンダリングされ、実際のx、yの位置の変更が有効にならないため、これは感じています。

これはこれまで私が行ってきたことです。

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 
    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="50dip" 
     android:text="@string/hello" 
     android:id="@+id/unbutt" 
     android:gravity="right|center_vertical" 
     /> 
    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="50dip" 
     android:text="@string/hello" 
     android:id="@+id/butt" /> 

</FrameLayout> 

コード:

import android.app.Activity; 
import android.os.Bundle; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.view.animation.Animation; 
import android.view.animation.Animation.AnimationListener; 
import android.view.animation.TranslateAnimation; 
import android.widget.TextView; 

public class Main extends Activity implements AnimationListener, OnClickListener 
{ 
    /** Called when the activity is first created. */ 

    private class BottomViewClick implements OnClickListener 
{ 

    @Override 
    public void onClick(View v) { 
     Toast.makeText(v.getContext(), "Second Click", 5).show(); 
    } 

} 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    TextView tv = (TextView)findViewById(R.id.butt); 
    tv.setBackgroundColor(0xffb71700); 
    tv.setOnClickListener(this); 

    TextView tv2 = (TextView)findViewById(R.id.unbutt); 
    tv2.setBackgroundColor(0xffb700ff); 
    tv2.setOnClickListener(new BottomViewClick()); 

} 

    private boolean revealed = false; 

    @Override 
    public void onClick(View v) { 
     Animation a ; 
     if(!revealed) 
      a = new TranslateAnimation(0f, -200f, 0f, 0f); 
     else 
      a = new TranslateAnimation(-200f, 0f, 0f, 0f); 
     a.setDuration(500); 
     a.setFillAfter(true); 
     a.setAnimationListener(this); 
     v.startAnimation(a); 
    } 

    @Override 
    public void onAnimationEnd(Animation animation) { 
     if(revealed) 
      revealed = false; 
     else 
      revealed = true; 
    } 

    @Override 
    public void onAnimationRepeat(Animation animation) { 
    } 

    @Override 
    public void onAnimationStart(Animation animation) { 
    } 
} 

答えて

4

あなたがタグでICSを持っているので、私はそれがあなたの目標が何であるかだと仮定します。その場合、使用しているAnimationオブジェクトは基本的にはAnimatorクラスを使用して廃止されます。これを行う古い方法は、物理的な場所が同じままである間に、Viewの視覚的な位置を移動するだけです。ビューのマージンを操作して自分で移動する必要があります。一方、ObjectAnimatorを使用すると、ビジュアルコンポーネントとともにオブジェクトを物理的に移動することができます。

http://android-developers.blogspot.com/2011/05/introducing-viewpropertyanimator.html

関連する問題