
当我以编程方式将视图A设置为GONE时,它将消失,并且它正下方的视图(B)将转到视图A的位置(如预期的那样).
但是,当我再次将相同的视图(A)设置为VISIBLE时,它会在视图B上显示.我不希望这样.我希望视图B回到原来的位置(在视图A下面),这是我认为会发生的事情(但事实并非如此).我怎样才能做到这一点?
先感谢您!
编辑 – 代码
package com.test;import androID.app.Activity;import androID.os.Bundle;import androID.vIEw.VIEw;import androID.vIEw.VIEw.OnClickListener;import androID.vIEw.animation.ScaleAnimation;import androID.vIEw.animation.transformation;import androID.Widget.linearLayout.LayoutParams;public class VIEwGoneEffectActivity extends Activity implements OnClickListener {private VIEw vIEwComEfeito = null;@OverrIDeprotected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.main); findVIEwByID(R.ID.outrolinear).setonClickListener(this); findVIEwByID(R.ID.segundo).setonClickListener(this); vIEwComEfeito = findVIEwByID(R.ID.outrolinear);}@OverrIDepublic voID onClick(VIEw vIEw) { if (vIEw.getID() == R.ID.outrolinear) { vIEw.startAnimation(new MyScaler(1.0f,1.0f,0.0f,500,vIEw,true)); }else if(vIEw.getID() == R.ID.segundo){ vIEwComEfeito.setVisibility(VIEw.VISIBLE); }}public class MyScaler extends ScaleAnimation { private LayoutParams mLayoutParams; private int mmarginBottomFromY,mmarginBottomToY; private boolean mVanishAfter = false; public MyScaler(float fromX,float toX,float fromY,float toY,int duration,VIEw vIEw,boolean vanishAfter) { super(fromX,toX,fromY,toY); setDuration(duration); mVanishAfter = vanishAfter; mLayoutParams = (LayoutParams) vIEw.getLayoutParams(); //int height = mVIEw.getHeight(); int height = vIEwComEfeito.getHeight(); mmarginBottomFromY = (int) (height * fromY) + mLayoutParams.bottommargin - height; mmarginBottomToY = (int) (0 - ((height * toY) + mLayoutParams.bottommargin)) - height; } @OverrIDe protected voID applytransformation(float interpolatedTime,transformation t) { super.applytransformation(interpolatedTime,t); if (interpolatedTime < 1.0f) { int newmarginBottom = mmarginBottomFromY + (int) ((mmarginBottomToY - mmarginBottomFromY) * interpolatedTime); mLayoutParams.setmargins(mLayoutParams.leftmargin,mLayoutParams.topmargin,mLayoutParams.rightmargin,newmarginBottom); vIEwComEfeito.getParent().requestLayout(); } else if (mVanishAfter) { vIEwComEfeito.setVisibility(VIEw.GONE); } }} }
这里是XML:
<?xml version="1.0" enCoding="utf-8"?> <linearLayoutxmlns: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>解决方法 您可以尝试将两个视图放在relativeLayout中并相对于彼此设置它们的位置. 总结
以上是内存溢出为你收集整理的Android – 调用GONE然后VISIBLE使视图显示在错误的位置全部内容,希望文章能够帮你解决Android – 调用GONE然后VISIBLE使视图显示在错误的位置所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)