android布局闪动,设置child.setvisibility(View.Visible)时,Android主屏幕出现效果闪烁问题...

我已经制作了一个示例应用程序,可以在视镜中浏览不同的布局.

XML基本上是(伪代码)

在Java代码中

public boolean onTouchEvent(MotionEvent event)

case MotionEvent.ACTION_DOWN {

oldTouchValue = event.getX()

} case MotionEvent.ACTION_UP {

//depending on Direction, do viewFlipper.showPrevious or viewFlipper.showNext

//after setting appropriate animations with appropriate start/end locations

} case MotionEvent.ACTION_MOVE {

//Depending on the direction

nextScreen.setVisibility(View.Visible)

nextScreen.layout(l, t, r, b) // l computed appropriately

CurrentScreen.layout(l2, t2, r2, b2) // l2 computed appropriately

}

上面的伪代码在屏幕上拖动时就像在主屏幕上一样,可以很好地在viewflipper中移动线性布局.

问题是当我执行nextScreen.setVisibility(View.VISIBLE)时.当下一个屏幕设置为可见时,它会在屏幕上闪烁,然后移动到适当的位置. (我猜它在0位置可见.)

有没有一种方法可以加载下一个屏幕而不使其在屏幕上闪烁?我希望它在屏幕外加载(显示),以免闪烁.

非常感谢您的时间和帮助!

解决方法:

1.我有完全相同的问题.我尝试将layout()和setVisible()调用切换为无效.

更新:

问题出在设置nextScreen视图的可见性上是正确的顺序.如果在调用layout()之前将可见性设置为VISIBLE,则您将注意到闪烁发生在位置0.但是,如果首先调用layout(),则它会被忽略,因为可见性已消失.我做了两件事来解决此问题:

>在第一个layout()调用之前将可见性设置为INVISIBLE.这与GONE的不同之处在于执行了layout()-您只是看不到它.

>异步将可见性设置为VISIBLE,因此首先处理layout()和相关消息

在代码中:

case MotionEvent.ACTION_DOWN:

nextScreen.setVisibility(View.INVISIBLE); //from View.GONE

case MotionEvent.ACTION_MOVE:

nextScreen.layout(l, t, r, b);

if (nextScreen.getVisibility() != View.VISIBLE) {

//the view is not visible, so send a message to make it so

mHandler.sendMessage(Message.obtain(mHandler, 0));

}

private class ViewHandler extends Handler {

@Override

public void handleMessage(Message msg) {

nextScreen.setVisibility(View.VISIBLE);

}

}

欢迎提供更优雅/更轻松的解决方案!

标签:flicker,homescreen,viewflipper,android,visible

来源: https://codeday.me/bug/20191009/1878925.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值