2010-12-21 72 views
0

我有一个小的但恼人的问题与动画在Android的意见。查看仍然存在但被动画移出后不可见

涉及什么: 我有一个FrameLayout在另一个FrameLayout包含在一个XML中。

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

     <ListView 
       android:id="@android:id/list" 
       android:layout_height="fill_parent" 
       android:layout_width="fill_parent"></ListView> 
     <FrameLayout 
       android:id="@+id/TopBanner" 
       xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content"> 
       <ImageView 
         android:id="@+id/ImageView01" 
         android:layout_width="fill_parent" 
         android:background="@drawable/topmenu" 
         android:layout_height="150dip"></ImageView> 

       <Gallery 
         android:id="@+id/Gallery01" 
         android:layout_width="fill_parent" 
         android:layout_height="wrap_content"></Gallery> 
     </FrameLayout> 
</FrameLayout> 

我也写了一个动画XML:

<?xml version="1.0" encoding="utf-8"?> 
<set 
     android:interpolator="@android:anim/bounce_interpolator" 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     fillEnabled="true" 
     android:fillBefore="true" 
     android:fillAfter="true"> 
     <translate 
       android:duration="500" 
       android:fromYDelta="0" 
       android:toYDelta="-80%" /> 
</set> 

我想是翻译上点击我内心的FrameLayout(topbanner)从活动视图,除了它的20%,在为了使它在我点击它时重新出现。一种顶级菜单。

我设法申请我的动画,但即使我的布局被翻译我可以触摸它,如果它仍然存在。任何建议?这是我的java代码:

@Override 
    protected void onCreate(Bundle savedInstanceState) { 

     super.onCreate(savedInstanceState); 
     UserSettings = getSharedPreferences("net.blabla_preferences", MODE_WORLD_WRITEABLE); 

     tab = getIntent().getExtras().getInt("net.blabla.FigureTab"); 

     setContentView(R.layout.layout_figure_list); 

     final Animation animation = AnimationUtils.loadAnimation(this, R.anim.animation_topbanner); 
     topbanner = (FrameLayout) findViewById(R.id.TopBanner); 


     topbanner.setOnClickListener(new OnClickListener() { 

      public void onClick(View v) { 
       v.startAnimation(animation); 
      } 
     }); 

     load(); 

    } 
+1

对于动画编写动画侦听器[animation.setAnimationListener],并在动画结束时尝试将topbanner的可见性更改为View.GONE。 – Varun 2010-12-21 18:37:15

回答

1

编辑: 自3.0 Honeycomb出现以来,情况发生了变化。有一个全新的动画系统可以利用,请看这里:Android Developer's Blog

动画不影响屏幕上视图的'物理'位置。如果你想让它实际移动,那么你需要调整视图的属性。

对于您的情况,更简单的解决方案是使用SDK中包含的SlidingDrawer小部件。既然你试图实现一个拉出菜单,这似乎是一个完美的选择。

相关问题