1つまたは 2 つのビュー (および) を含むことができるLinearLayout
( ) があります(それらは または のいずれかです)。これは別の( ) にあります。LayoutContentView
SubView1
SubView2
TextView
ImageView
layout
LinearLayout
MyScreenLayout
LayoutContentView
でアニメーションを作成して、 でその一部だけを移動して表示できるようにしたいと考えていMyScreenLayout
ます。
これらのレイアウトはどちらも、setClipChildren(false);
子がそれ自体の外に描画できるようにするためのものです。
さまざまなパラメーターに応じて、コンテンツのサイズと表示するコンテンツのサイズを変更できます。
基本的に、上から下に拡張して 2 つのサブビューを表示し、下から上に非拡張して 2 番目のサブビューのみを表示します。拡張する前に のサイズを大きくしてLayoutContentView
、2 つのサブビューを表示できるようにします。拡張を解除した後、 のサイズを小さくしてLayoutContentView
、2 番目のサブビューのみを表示できるようにし、画面に他の要素用のスペースを確保します。 .
これが私の支出と非支出の方法ですLayoutContentView
:
mLayoutContentView.clearAnimation();
float yFrom = 0.0F;
float yTo = 0.0F;
float xFrom = 0.0F;
float xTo = 0.0F;
if (expend) { // if we expend
// I change the height of my LayoutContentView so it we can show it's two subviews
final android.view.ViewGroup.LayoutParams lp = mLayoutContentView.getLayoutParams();
lp.height = subView1H + subView2H;
setLayoutParams(lp);
invalidate();
// we start the animation so it shows only the second subview
yFrom = -subView1H;
// and we animate from top to bottom until it shows the two subviews
yTo = 0;
} else { // if we un-expend
// we animate from bottom to top starting by showing the two subviews
yFrom = 0;
// and progressively hiding the first subview and showing only the second subview
yTo = -subView1H;
}
Animation anim = new TranslateAnimation(xFrom, xTo, yFrom, yTo);
anim.setDuration(1000);
anim.setFillAfter(true);
anim.setFillEnabled(true);
anim.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
if (!expend) {
// if we un expend at the end of the animation we can set the size of LayoutContentView to the size of the second subview again
final android.view.ViewGroup.LayoutParams lp = mLayoutContentView.getLayoutParams();
lp.height = subView2H;
mLayoutContentView.setLayoutParams(lp);
invalidate();
}
}
});
mLayoutContentView.startAnimation(anim);
私がアニメーションを作成した方法はLayoutContentView
、2つのサブビューを含むレイアウトに適用する必要があり、アニメーションをstartAnimation()
実行しません。を使用しようとしましたLayoutAnimationController
が、 でアニメーションを実行する代わりに、各子でアニメーションLayoutContentView
を実行します...また、各子でアニメーションを自分で実行しようとしましたが、理由がわかりません.2番目のサブビューは表示されません。
を使用しようとするたびにHierarchyViewer
、アニメーションによる変更が見られます。
誰かが解決策を知っているか、同じ問題に直面して良い解決策を見つけましたか?
編集:background
色を設定TextView
してアニメーションで移動すると、アニメーションのbackground
後に塗りつぶしパラメータを設定した場合でも、背景が元の位置またはそのようなものに戻るため、両方の に背景色を設定すると、の背景のSubView
一方SubView
が他方の背景を隠します...また、アニメーションの後、一方SubView
がまだそのレイアウトの外にある場合にも問題があります。アニメーション中にも問題があるので、ここでも意図したことに制限を加えます。