Android-调用GONE然后可见会使视图显示在错误的位置

Android-调用GONE然后可见会使视图显示在错误的位置,android,user-interface,view,visibility,Android,User Interface,View,Visibility,我有两个视图,A和B,视图A在视图B的上方(都是线性布局) 当我以编程方式将视图A设置为不存在时,它将消失,并且它正下方的视图(B)将转到视图A的位置(如预期的那样) 但是,当我再次将同一视图(A)设置为可见时,它将显示在视图B上。我不希望这样。我希望视图B回到其原始位置(视图A下方),这是我认为会发生的情况(但事实并非如此)。我该怎么做 提前谢谢你 编辑代码 package.com.test; 导入android.app.Activity; 导入android.os.Bundle; 导入and

我有两个视图,A和B,视图A在视图B的上方(都是线性布局)

当我以编程方式将视图A设置为不存在时,它将消失,并且它正下方的视图(B)将转到视图A的位置(如预期的那样)

但是,当我再次将同一视图(A)设置为可见时,它将显示在视图B上。我不希望这样。我希望视图B回到其原始位置(视图A下方),这是我认为会发生的情况(但事实并非如此)。我该怎么做

提前谢谢你

编辑代码
package.com.test;
导入android.app.Activity;
导入android.os.Bundle;
导入android.view.view;
导入android.view.view.OnClickListener;
导入android.view.animation.ScaleAnimation;
导入android.view.animation.Transformation;
导入android.widget.LinearLayout.LayoutParams;
公共类ViewGoneEffectActivity扩展了活动实现OnClickListener{
私有视图viewComEfeito=null;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
findviewbyd(R.id.outroLinear).setOnClickListener(this);
findviewbyd(R.id.segundo).setOnClickListener(this);
viewComEfeito=findViewById(R.id.outroLinear);
}
@凌驾
公共void onClick(视图){
if(view.getId()==R.id.outroLinear){
view.startAnimation(新的MyScaler(1.0f、1.0f、1.0f、0.0f、500、view、,
是的);
}else if(view.getId()==R.id.segundo){
viewComEfeito.setVisibility(View.VISIBLE);
}
}
公共类MyScaler扩展了ScaleAnimation{
私有布局参数mLayoutParams;
私人内特马尔金波顿弗罗米,马尔金波顿玩具;
私有布尔值mVanishAfter=false;
公共MyScaler(float fromX、float toX、float fromY、float toY、,
整数持续时间、视图、布尔值消失后){
超级(fromX,toX,fromY,toY);
设置持续时间(持续时间);
mVanishAfter=之后消失;
mLayoutParams=(LayoutParams)视图。getLayoutParams();
//int height=mView.getHeight();
int height=viewComEfeito.getHeight();
mMarginBottomFromY=(int)(高度*fromY)+mLayoutParams.bottomMargin-高度;
mMarginBottomToY=(int)(0-((高度*玩具)+mLayoutParams.bottomMargin))-高度;
}
@凌驾
受保护的无效应用转换(浮点插值时间,
变换(t){
超级应用转换(插值时间,t);
如果(插值时间<1.0f){
int newMarginBottom=mMarginBottomFromY+(int)((mMarginBottomToY-mMarginBottomFromY)*插值时间);
mLayoutParams.setMargins(mLayoutParams.leftMargin、mLayoutParams.topMargin、mLayoutParams.righmargin、newMarginBottom);
viewComEfeito.getParent().requestLayout();
}否则,如果(MVA轴){
viewComEfeito.setVisibility(View.GONE);
}
}
}
}

下面是XML:

 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<LinearLayout
    android:id="@+id/outroLinear"
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Welcome to the real world" />

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="No" />

                <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Wow! =P" />

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Free your mind!" />

                <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="In Tylor we trust" />

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="First rule of fight club is" />

</LinearLayout>

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    android:id="@+id/segundo" />


 </LinearLayout>


您可以尝试将两个视图都放在一个相对区域内,并设置它们彼此的相对位置。

尝试将布局a和B都放在另一个线性布局中,例如具有以下属性的C:-高度环绕内容,方向垂直它将根据您的需要工作:)

您必须调用测量(宽度,高度)视图更改为可见后。
否则,视图将以不同的方式显示。

请添加一些代码,让我们知道您的问题……我用代码编辑了我的问题。提前谢谢!
 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<LinearLayout
    android:id="@+id/outroLinear"
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Welcome to the real world" />

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="No" />

                <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Wow! =P" />

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Free your mind!" />

                <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="In Tylor we trust" />

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="First rule of fight club is" />

</LinearLayout>

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    android:id="@+id/segundo" />


 </LinearLayout>