奇妙なものがあります。私は非常に単純な例にそれを持ってきた。本当にそれを理解することはできません。LinearyLayoutは、高さが0になるとサイズ変更されません。
私はLinearLayout内にLinearLayoutを持っています。アニメーションを使って子のサイズを変更したいのですが(これは時には扱いがあります)。レイアウトXMLがここにあります。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical">
<!-- Lots more controls will appear above -->
<LinearLayout android:layout_width="fill_parent" android:layout_height="0dp" android:id="@+id/animation_subject">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
android:gravity="center" />
</LinearLayout>
<!-- Lots more controls will appear below -->
</LinearLayout>
<Button android:text="Slide it Down!" android:layout_width="fill_parent" android:layout_height="wrap_content" android:onClick="btnDoAnimDown_OnClick" />
</LinearLayout>
ここでわかるように、ボタンがあります。ここにはそのボタンのコードがあります。
public void btnDoAnimDown_OnClick(View v)
{
View pnlSlider = findViewById(R.id.animation_subject);
pnlSlider.measure(1000, 1000);
DropDownAnim anim = new DropDownAnim(pnlSlider, pnlSlider.getMeasuredHeight(), true);
anim.setDuration(2000);
pnlSlider.startAnimation(anim);
return;
}
今すぐ実行すると、それは滑り落ちることはありません。まったく。しかし、ButtonをLinearLayoutに移動して、Overviewという名前のLinearLayoutをChild LinearLayoutの後に置くと、それは扱いになります!このように...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical">
<!-- Lots more controls will appear above -->
<LinearLayout android:layout_width="fill_parent" android:layout_height="0dp" android:id="@+id/animation_subject">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
android:gravity="center" />
</LinearLayout>
<!-- Lots more controls will appear below -->
<Button android:text="Slide it Down!" android:layout_width="fill_parent" android:layout_height="wrap_content" android:onClick="btnDoAnimDown_OnClick" />
</LinearLayout>
</LinearLayout>
これは、予想どおり正確にスライドします。明らかに、親レイアウトでは何かが起こっています... getMeasuredHeight()は正しい値を返しますので、アニメーションは実際には実行されません!
これはアニメーションクラスですが、私は何か愚かなことを逃していますか?おそらく午前!
import android.util.Log;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Transformation;
public class DropDownAnim extends Animation {
int targetHeight;
View view;
boolean down;
public DropDownAnim(View view, int targetHeight, boolean down) {
this.view = view;
this.targetHeight = targetHeight;
this.down = down;
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
int newHeight;
if (down) {
newHeight = (int) (targetHeight * interpolatedTime);
} else {
newHeight = (int) (targetHeight * (1 - interpolatedTime));
}
Log.d("new height", String.valueOf(newHeight));
view.getLayoutParams().height = newHeight;
view.requestLayout();
}
@Override
public void initialize(int width, int height, int parentWidth,
int parentHeight) {
super.initialize(width, height, ((View)view.getParent()).getWidth(), parentHeight);
}
@Override
public boolean willChangeBounds() {
return true;
}
}
どのようなヘルプも素晴らしいでしょう!
ない正確に解決策が、聞かせて:
そしてここでは、ボタンclicクリックのコードです:ここに は、私が唯一の親のレイアウトにIDを追加、XMLのコードですボタンが表示されているかどうかを確認します。それはそのように機能しますか? – Urban
これをクリックしてテストすることはできません。私はそこに別のオブジェクトを入れてそれを試みます。 –
いいえ、サイコロはありません。次の兄弟がアニメーションの原因となるボタンでない場合は、それを実行しません。どのように奇妙です。ここでは非常に混乱しています。 –