--
このメールは Google グループのグループ「日本Androidの会」に登録しているユーザーに送られています。
このグループから退会し、グループからのメールの配信を停止するには android-group-j...@googlegroups.com にメールを送信してください。
このグループに投稿するには android-g...@googlegroups.com にメールを送信してください。
http://groups.google.com/group/android-group-japan からこのグループにアクセスしてください。
その他のオプションについては https://groups.google.com/d/optout にアクセスしてください。
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// 選択されたアイテムのレイアウトを取得
LinearLayout ll = (LinearLayout) view;
ImageView image = (ImageView) ll.findViewById(R.id.product_img);
// 一番親のレイアウトを取得
RelativeLayout parentLayout = (RelativeLayout) mView.findViewById(R.id.parentLayout);
// 画面全体に対しての移動前の画像の位置を取得
final int[] anchorPos = new int[2];
image.getLocationOnScreen(anchorPos);
// 画面全体に対しての横位置
float beforeX = anchorPos[0];
// 画面全体に対しての縦位置 - Action Barの高さ - ステータスバーの高さ
float beforeY = anchorPos[1]
- getActivity().getActionBar().getHeight()
- getStatusBarHeight();
// 移動アニメーション用の画像を生成
ImageView movingImage = new ImageView(getActivity());
movingImage.setImageDrawable(image.getDrawable());
movingImage.setLayoutParams(new RelativeLayout.LayoutParams(
image.getWidth(), image.getHeight()));
parentLayout.addView(movingImage);
// 元のイメージを消す
image.setVisibility(View.INVISIBLE);
// 移動先を指定
float afterX = (displayMetrics.widthPixels / 2);
float afterY = 10f;
// 画像をアニメーションで移動
ObjectAnimator productAnimationX = ObjectAnimator.ofFloat(
movingImage, "x", beforeX, afterX);
ObjectAnimator productAnimationY = ObjectAnimator.ofFloat(
movingImage, "y", beforeY, afterY);
productAnimationX.setDuration(500);
productAnimationY.setDuration(500);
productAnimationX.start();
productAnimationY.start();
}
}
zaki です。View は直近の親になっている ViewGroup の外側に自身を描画することはできません。どうしても 1 の中の任意の位置に移動させたいならImageView を 1 の子としてレイアウトを作成しないと無理ではないかと思います。
2014-09-25 15:56 GMT+09:00 Kento <kento...@gmail.com>:
こんにちは。
移動アニメーションで詰まってしまったのでお力を貸してください。
現在、以下のようなレイアウトになっています。
1 2 3
Relative ---Linear(A)---Button
---Linear(B)---ImageView
1が一番親で、その中に2つのLinearLayoutがあり、それぞれにButtonとImageViewがあります。
Buttonを押してImageViewをアニメーションで移動させたいと思っています。
このときRelativeLayout(もしくはActivity全体)の座標で指定した位置に移動させたいと思っているのですが、
ImageViewの直近の親である、LinearLayout(B)に対する座標の位置に移動してしまいます。
ObjectAnimator、TranslateAnimationなどで試行錯誤しましたが、どうしても画面全体での座標指定ができません。
ちなみに移動先座標は画面の大きさを取得して動的に決めるつもりです。
解決方法をご存知の方がいらっしゃいましたらよろしくお願いいたします。
--
このメールは Google グループのグループ「日本Androidの会」に登録しているユーザーに送られています。
このグループから退会し、グループからのメールの配信を停止するには android-group-japan+unsub...@googlegroups.com にメールを送信してください。
このグループに投稿するには android-g...@googlegroups.com にメールを送信してください。
http://groups.google.com/group/android-group-japan からこのグループにアクセスしてください。
その他のオプションについては https://groups.google.com/d/optout にアクセスしてください。
--
YAMAZAKI Makoto