我有xml文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show" />
<Button
android:id="@+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/btn1"
android:text="Hide" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/layout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
</LinearLayout>
<LinearLayout
android:id="@+id/layout2"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#a70000"
android:orientation="vertical"></LinearLayout>
</LinearLayout>
</RelativeLayout>
&#13;
现在我想点击按钮显示/隐藏来显示/隐藏layout2。 我用过代码:
btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (ln2.getVisibility() != View.VISIBLE) {
ln2.setVisibility(View.VISIBLE);
ln2.startAnimation(AnimationUtils.loadAnimation(MainActivity.this, R.anim.translate_in));
}
}
});
btn2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (ln2.getVisibility() == View.VISIBLE) {
ln2.setVisibility(View.GONE);
ln2.startAnimation(AnimationUtils.loadAnimation(MainActivity.this, R.anim.translate_out));
}
}
});
&#13;
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:duration="350"
android:fromYDelta="100%p"
android:toYDelta="0" />
</set>
&#13;
animation_out.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="350"
android:fromYDelta="0"
android:toYDelta="100%p" />
</set>
&#13;
但是当layout2显示我在show layout2之前显示底部的步伐相同: enter image description here
我该如何解决?当show hide layout2但是它无效时,我为layout1设置了用户设置布局参数。 非常感谢你!