2017-02-28 5 views
0

キャプチャボタンをクリックしたときにfadeIn-fadeOutのようなアニメーションを作りたいと思います。 animatedViewでandroid:fromAlpha = "1.0"、android:toAlpha = "0.0"と設定した場合は動作しますが、逆にする必要があります。 ここに私のレイアウト:アニメーションalpha(SurfaceViewの下)が動作しない

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/layout" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="horizontal"> 

<SurfaceView 
    android:id="@+id/preview" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" /> 

<View 
    android:id="@+id/animated_view" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@android:color/black" 
    android:alpha="0.0"/> 

<Button 
    android:id="@+id/button_capture" 
    android:layout_width="50dp" 
    android:layout_height="50dp" 
    android:layout_alignParentEnd="true" 
    android:layout_alignParentRight="true" 
    android:layout_centerVertical="true" /> 
</RelativeLayout> 

ここに私のアニメーションのxml:

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" 
android:interpolator="@android:anim/accelerate_interpolator"> 
<alpha 
    android:duration="500" 
    android:fromAlpha="0.0" 
    android:repeatCount="1" 
    android:repeatMode="reverse" 
    android:toAlpha="1.0" 
    /> 
</set> 

そして、それは私がそれを実行する方法は次のとおりです。

animClick = AnimationUtils.loadAnimation(getApplicationContext(), 
      R.anim.click); 

@OnClick(R.id.button_capture) 
void onCaptureClick() { 
    camera.takePicture(null, null, jpegCallback); 
    animatedView.startAnimation(animClick); 
} 

、何が私が間違ってやっている、どうなりますか?

答えて

0

あなたのレイアウトを正しく配置していないということは実際にアニメーションに問題はありません あなたが望むものと同じではないが、あなたがそれをどのように修正するのかを理解することができれば、レイアウトを見てください。

あなたは高さ==>すべてのものに対してmatch_parentを設定しているため、ビューをアニメーション化できないことがあります。

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="horizontal"> 

    <SurfaceView 
     android:id="@+id/preview" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" /> 

    <View 
     android:id="@+id/animated_view" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@mipmap/ic_launcher" 
     /> 

    <Button 
     android:id="@+id/button_capture" 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:layout_alignParentEnd="true" 
     android:layout_alignParentRight="true" 
     android:layout_centerVertical="true" /> 
</RelativeLayout> 

ここで更新されたxmlはうまく動作します!

+0

しかし、私はViewを完全にオーバーラップSurfaceView – Nikita

+0

あなたは更新された答えをチェックするかもしれませんこのxmlファイルを使用してください –

関連する問題