setVisibility 在 ViewFlipper 中不起作用
我试图通过 setVisibility to GONE 禁用 ViewFlipper 中的 TextView,但无法让它按照我想要的方式运行。我的代码:
switch(index) {
case 0:
//Do Stuff
findViewById(R.id.o2).setVisibility(8);
findViewById(R.id.o3).setVisibility(8);
break;
case 1:
//Do Stuff
findViewById(R.id.o3).setVisibility(8);
break;
case 2:
//Do Stuff
break;
}
我的 XML
<ViewFlipper android:id="@+id/oFlipper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:flipInterval="1000"
android:inAnimation="@anim/push_up_in"
android:outAnimation="@anim/push_up_out">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textSize="26sp"
android:text="Opponents:"/>
<TextView android:id="@+id/o1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textSize="26sp"
android:visibility="gone"/>
<TextView android:id="@+id/o2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textSize="26sp"
android:text="2"/>
<TextView android:id="@+id/o3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textSize="26sp"
android:text="3"/>
</ViewFlipper>
我已经尝试过 .startFlipping() 之前和之后的代码,但无济于事。看起来 TextView 消失了一次视图翻转,然后又重新出现。但即使在 XML 文件中硬编码为 GONE,该视图也只是空白,而不是将其他视图移至其位置。我基本上只是希望 TextView 完全消失。有什么办法可以做到这一点吗?
I'm trying to disable a TextView within a ViewFlipper via setVisibility to GONE and cannot get it to act like I'm wanting. My code:
switch(index) {
case 0:
//Do Stuff
findViewById(R.id.o2).setVisibility(8);
findViewById(R.id.o3).setVisibility(8);
break;
case 1:
//Do Stuff
findViewById(R.id.o3).setVisibility(8);
break;
case 2:
//Do Stuff
break;
}
my XML
<ViewFlipper android:id="@+id/oFlipper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:flipInterval="1000"
android:inAnimation="@anim/push_up_in"
android:outAnimation="@anim/push_up_out">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textSize="26sp"
android:text="Opponents:"/>
<TextView android:id="@+id/o1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textSize="26sp"
android:visibility="gone"/>
<TextView android:id="@+id/o2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textSize="26sp"
android:text="2"/>
<TextView android:id="@+id/o3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textSize="26sp"
android:text="3"/>
</ViewFlipper>
I've tried the code before and after .startFlipping() to no avail. It appears that the TextView is gone for one view flip and then reappears. But even when hardcoded to GONE in the XML file the view is simply blank rather than shifting the other views up in its place. I basically just want the TextView to go away completely. Is there any way to accomplish this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我也有同样的问题。使用
INVISIBLE
比GONE
更好,视图不会显示,但它仍然占用一个时间段,例如,您获得前一个视图的时间是应有的时间的两倍。通过从 ViewFlipper 添加和删除子视图,我已经按照我想要的方式工作了。在我将每个子视图设置为
GONE
或VISIBLE
(在 onResume 中)的代码中,我现在使用 .removeAllViews() 将它们全部从脚蹼中删除,然后如果我设置它们可见我用 .addView(mView); 将它们添加回来当 ViewFlipper 为空时,它甚至看起来会做正确的事情。I have had the same issue. Using
INVISIBLE
is better thanGONE
the view is not displayed but it still takes up a timeslot e.g. you get the previous view for twice as long as you should.I have got things working the way I want by adding and removing the child views from the ViewFlipper. In the code where I was setting each sub view to
GONE
orVISIBLE
(in onResume) I now remove them all from the flipper with .removeAllViews() then if I was setting them to visable I add them back in with .addView(mView); It even looks to do the right thing when the ViewFlipper is empty.