So I am trying to make an animation, I have a Map and I want to make it move down to make place for a layout ot be shown. The animation works perfectly, the map moves down; and the layout is visible (the layout contains a button, textEdit and a textView). So my problem is that I can't use these views, I cant write on the EditText, I can't click the button; they're visible; but I can't use them. And also; when I click or drag in the free space on the new layout, the Map will move, it's just like the map is still there. I hope that my problem is clear. Here the code I am using:
Xml File:
<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();
}
}