所以我正在尝试制作动画,我有一张地图,我想让它向下移动,以便为显示的布局腾出空间。 动画效果很好,地图向下移动;并且布局是可见的(布局包含按钮,textEdit和textView)。所以我的问题是我无法使用这些视图,我无法在EditText上写,我无法点击按钮;它们是可见的;但我不能用它们。 并且;当我点击或拖动新布局上的自由空间时,地图会移动,就像地图仍在那里一样。我希望我的问题很明确。 这是我正在使用的代码:
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();
}
}
答案 0 :(得分:1)
好吧,这是因为你没有使用属性动画为地图设置动画。你正在使用的动画使它看起来像地图已经移动但实际上它没有。另一方面,PropertyAnimator移动整个对象。
http://developer.android.com/guide/topics/graphics/prop-animation.html#object-animator