2011-10-19 8 views
8

私は非常に面白いですが、迷惑なエラーに直面しています。線形レイアウトでは、マージンをマイナスで使用して別の線形レイアウトを隠してしまいました。ユーザーがリストからタイプを選択すると、Translational Animationを使用してレイアウトを前面に出します。 (私の主なレイアウトはスクロールビューに囲まれています)それは生きていて、スクロールを止めると再び死んでしまいます...なぜこのようなことが起こっているのか判断できませんでした。ヘルプ....EditTextはアニメーションの後にスクロールし、スクロールすると元に戻ります...... ......?

は、私も自分のアプリのこの迷惑な振る舞いを示す下のビデオのリンクを貼り付けている

http://www.dailymotion.com/video/xlskk8_android-app-edit-text-error_tech

スクロールビューの内側

私のレイアウトXMLは

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:orientation="vertical" 
> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:layout_marginLeft="10dip" 
android:layout_marginRight="10dip" 
android:layout_marginTop="-110dip" 
android:layout_marginBottom="5dip" 
android:id="@+id/notes_editor" 
android:orientation="vertical" 
> 
<EditText 
android:id="@+id/enter_note" 
android:layout_height="wrap_content" 
android:layout_width="fill_parent" 
android:maxLines="2" 
android:lines="2"> 
</EditText> 
<Button 
android:id="@+id/save_note" 
android:layout_height="wrap_content" 
android:layout_width="wrap_content" 
android:text="Save" /> 

</LinearLayout> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:layout_marginTop="-10dip" 
android:id="@+id/notes_list" 
android:orientation="vertical" 
> 
</LinearLayout> 

</LinearLayout> 

あるボタンの下に空のリニアレイアウトを動的に子を追加するために使用されている他のすべてのものは、適切にこの異常な挙動を示すだけエディットテキストをその機能を実行しているビュー。

アニメーションに使用されるコードslider.setFillAfter(true);を適用したとき、ここで

public void animateEditor() 
{ 
     slider = new TranslateAnimation(0, 0, 0,180); 
     slider.setDuration(1250); 
     slider.setFillAfter(true); 
     notes_list.startAnimation(slider); 
     notes_editor.startAnimation(slider); 
} 

答えて

23

下に問題のあるコードは、ビューの画像をアニメーション化しますが、私はアニメーションを下にスライドした後、それらを見るとき、彼らは(た理由だではない実際のビュー実際のビューがレイアウトの後ろにあり、正面にそのイメージがあるからです。

この問題の解決策は、次のコードを適用することです。

その後、
slider.setFillAfter(false); 
slider.setFillBefore(false); 
// OR you can directly write 
slider.setFillEnabled(false); 

とアニメーションのリスナーを設定し、以下の方法を使用して、新しい場所での実際のビューを表示する:

法の上使用して、アニメーションの最後に新しい位置にビューを置く
public void onAnimationEnd(Animation a) 

。実際にアニメーションが終了して点滅してしまう前に呼び出されるというアンドロイドアニメーションリスナメソッドの問題による点滅の別の問題がまだ残っています。そのための難しい解決策は、次のコード行を1行目public void onAnimationEnd(Animation a)の方法。

// in my case animation applied to notes_editor so the code will be 
notes_editor.clearAnimation(); 
+0

私はドラッグアンドドロップに取り組んでいます。私はそのアニメーションを下に動かすまで持続させたいと思っていますが、fillafterを偽に設定すると、あなたは元気に戻るでしょうか? –

+0

私が説明したように、アニメーションの終了時にonAnimationEnd(Animation a)メソッドが呼び出されるアニメーションのリスナーを使用する必要があります。そのとき、アニメーションの後の新しい位置にビューを配置する必要があります。 SetFillAfter(true)は、アニメーションの途中でアニメーションの終わりにビューのイメージを保持することを意味します。完全な機能を持つビューではなくアニメーション化されているビューのイメージだけです.fillafterはビューのイメージを新しい場所に置きますtouch bounds –

+0

これはほとんど私のために働いていましたが、時折ちらつきがありました。私はレイアウトの更新を遅らせることで問題を解決することが分かった。つまり、layout.post(Runnable)コンストラクトを使用します。 –

関連する問題