2014-02-26 10 views
0

所以我想做一個動畫,我有一個地圖,我想讓它向下移動,使佈局不顯示。 動畫效果完美,地圖向下移動;並且佈局是可見的(佈局包含一個按鈕,textEdit和一個textView)。所以我的問題是我不能使用這些視圖,我不能寫在EditText上,我不能點擊按鈕;他們是可見的;但我不能使用它們。 還;當我點擊或拖動新佈局的空閒空間時,地圖會移動,就像地圖仍然在那裏。我希望我的問題清楚。 在這裏,我使用的代碼:地圖佈局動畫製作不好android

XML文件:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#E8E8E8"> 

      <!-- Champs de saisie pour effectuer la recherche: --> 

    <RelativeLayout 
     android:id="@+id/Layout" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     >  

     <Button 
      android:id="@+id/Cacher" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="Cacher" 
      android:textSize="15sp" 
      android:onClick="onClickCacher" 
      android:background="#EEEEEE"/> 

     <TextView 
      android:id="@+id/CaptionRecherche" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Entrer l'emplacement que vous cherchez: " 
      android:textSize="20sp" 
      android:layout_marginTop="7dp" 
      android:layout_marginLeft="20dp" 
      android:layout_below="@id/Cacher" 
      /> 

     <EditText 
      android:id="@+id/Recherche" 
      android:layout_width="250dp" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_marginTop="10dp" 
      android:hint="Salle, Deparetement..." 
      android:layout_marginLeft="20dp" 
      android:layout_marginBottom="20dp" 
      android:maxLength="100" 
      android:paddingTop="5dp" 
      android:paddingBottom="5dp" 
      android:maxLines="1" 
      android:layout_below="@id/CaptionRecherche" 
      /> 
     </RelativeLayout> 
       <!-- La map: --> 
    <LinearLayout 
     android:id="@+id/MapLayout" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     > 

     <fragment 
      android:id="@+id/map" 
      android:name="com.google.android.gms.maps.MapFragment" 
      android:layout_width="match_parent" 
      android:layout_height="fill_parent" 
      /> 

    </LinearLayout> 
</RelativeLayout> 

MainActivity:

protected static LinearLayout MapLayout; 
    protected TranslateAnimation animationUp; 
    protected RelativeLayout RLayout; 

    public static ViewTreeObserver vto; 
@Override 
    protected void onCreate(Bundle savedInstanceState) { 

RLayout = (RelativeLayout)findViewById(R.id.Layout); 
     MapLayout = (LinearLayout)findViewById(R.id.MapLayout); 
     Toast.makeText(context, "MapLayout: "+MapLayout.toString(), Toast.LENGTH_LONG).show(); 
     //Solution found dans: http://stackoverflow.com/questions/7733813/how-can-you-tell-when-a-layout-has-been-drawn 
     vto = RLayout.getViewTreeObserver(); 
     vto.addOnGlobalLayoutListener(new GlobalLayoutListener(RLayout, context)); 
       MapLayout.startAnimation(GlobalLayoutListener.animationDown); 
     RLayout.setVisibility(View.VISIBLE); 
} 

GlobalLayoutListener:

public class GlobalLayoutListener implements OnGlobalLayoutListener { 

    RelativeLayout layout; 
    Context context; 
    public static int LHeight; 
    public static TranslateAnimation animationDown; 

    public GlobalLayoutListener(RelativeLayout layout, Context context){ 
     this.layout = layout; 
     this.context = context; 

    } 
    Animation.AnimationListener listener = new AnimationListener() { 

     @Override 
     public void onAnimationStart(Animation animation) { 
      // TODO Auto-generated method stub 

     } 

     @Override 
     public void onAnimationRepeat(Animation animation) { 
      // TODO Auto-generated method stub 

     } 

     @Override 
     public void onAnimationEnd(Animation animation) { 
      layout.setVisibility(View.VISIBLE); 

     } 
    }; 
    @Override 
    public void onGlobalLayout() { 
     layout.getViewTreeObserver().removeGlobalOnLayoutListener(this); 
     int height = layout.getMeasuredHeight(); 
     LHeight = height; 
     animationDown = new TranslateAnimation(MainActivity.MapLayout.getX(), MainActivity.MapLayout.getY(), MainActivity.MapLayout.getY(), height); 
     animationDown.setDuration(1000); 
     animationDown.setFillAfter(true); 
     Toast.makeText(context, "LayoutHeightttttttttt (Message dans the other classe ya baa): "+LHeight, 3000).show(); 
    } 

} 

回答