内部に 3 つの Relative Relayouts を持つ RelativeLayout があります。第 2 レベルの相対レイアウトには、ダウンロードされた imageView があり、サイズ (高さ、幅) が異なる場合があります。imageView が自分のレイアウトに合っているかどうかを確認したい。
私の第 2 レベルの相対レイアウトは次のようになります。
<RelativeLayout
android:id="@+id/tv_show_image_layout"
android:layout_width="400dp"
android:layout_height="200dp">
<ImageView
android:id="@+id/tvshow_imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="matrix"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:src="@drawable/dummy" />
</RelativeLayout>
1) 画像が小さすぎる場合は、レイアウトの高さに合わせて拡大縮小する必要があります
2) レイアウトと同じサイズの画像ならOK。
3) 画像が大きすぎる場合は、アニメーションを追加してゆっくりと上下に移動する必要があります
アニメーションを動かすために、私はこのコードを使用し、うまく動作します (ハードコードされた値を入れた場合):
TranslateAnimation animation = new TranslateAnimation(0.0f, 0.0f,
-20.0f, 120.0f); // new TranslateAnimation(xFrom,xTo, yFrom,yTo)
animation.setDuration(9000); // animation duration
animation.setRepeatCount(15); // animation repeat count
animation.setRepeatMode(2); // repeat animation (left to right, right to left )
//animation.setFillAfter(true);
show_image.startAnimation(animation); // start animation
しかし、アニメーションの移動範囲を設定するための画像の高さの正しい値を取得できないことが主な問題です。
imageView 範囲でのみ上下に移動するアニメーションを開始するにはどうすればよいですか?