アニメーションでクリック可能なImageViewの場所の変更 - アンドロイド
-
25-09-2019 - |
質問
私はRelativeLayout内部に含まれますImageViewのを持っています。 ImageViewのをクリックすると、私はそれを下に移動するために翻訳したアニメーションで全体RelativeLayoutをアニメーションます。
私は再びImageViewのをクリックします(それの新しい場所に)それを移動することになっています。はバックアップですが、それはできません。 ImageViewのはスタート地点私がクリックした場合しかし、それは「パネル」は、バックアップ全体を移動しません。なぜImageViewのは、少なくとも限り、それのクリック可能として... relativelayoutで動いていません。実際の画像が動いているが、それはクリッカブルだスポットはありません。
ここでは、レイアウトのための私のXMLは次のとおりです。
<RelativeLayout
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_width="fill_parent"
android:layout_height="120px"
android:layout_marginTop="-106px"
android:id="@+id/chatbox"
android:visibility="invisible">
<TextView
android:layout_width="fill_parent"
android:layout_height="106px"
android:background="#000000"
android:id="@+id/chattext" />
<ImageView
android:layout_width="20px"
android:layout_height="14px"
android:id="@+id/chatbubble"
android:layout_below="@id/chattext"
android:src="@drawable/chatbubble" />
</RelativeLayout>
編集:私はアニメーションが完了した後、所定の位置にパネルを保持するためにAnimation.setFillAfter(true)を使用していることを追加する必要があります。
解決
このアニメーションは、実際にビューの位置には影響を与えませんので、彼らはちょうどそれらを描くです。だから、新しい場所でハンドルをクリックし、あなたは場所にあり、何か(すなわち、目に見えないでframeLayout)を持っています。またはビューが実際の場所に移動しますので、あなたは、アニメーションを完全にあなたの意見の余白を変更することができます。
他のヒント
私は同じ問題を抱えていたとコンスタンチンBurovが言ったように私が見つけた最善の解決策は、あなたのアニメーションにAnimationListenerを追加し、そのリスナーにビューを自分で移動することです。
animation.setFillAfter(false);
AnimationListener animListener = new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
RelativeLayout.LayoutParams relativeLayoutParams = (LayoutParams) yourView.getLayoutParams();
//To avoid the flicker
yourView.clearAnimation();
relativeLayoutParams.setMargins(0, 0, 0, Utils.dpToPx(activity, newPositionDp);
yourView.setLayoutParams(relativeLayoutParams);
}
};
animation.setAnimationListener(animListener);
Utils.dpToPxがあまりにも有用である可能性がある。
public final static int dpToPx(Context context, int dp) {
return ((int)((dp * context.getResources().getDisplayMetrics().density) + 0.5));
}
所属していません StackOverflow