在MapView上产生波纹动画效果

时间:2015-10-20 14:30:11

标签: android android-animation android-mapview

有没有办法在MapView上创建连锁效果?

我的布局显示在帖子的末尾。 我知道header_container,它适用于不同类型的视图,但不适用于MapView。

我想要的是对map_viewselectableItemBackground的不可分割的涟漪效应。

为了达到这个目的,我尝试将它们放在RelativeLayout中并在它们上面创建带有<?xml version="1.0" encoding="utf-8"?> <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:card_view="http://schemas.android.com/apk/res-auto" xmlns:map="http://schemas.android.com/tools" android:id="@+id/cv_root" android:layout_width="match_parent" android:layout_height="wrap_content" card_view:cardCornerRadius="@dimen/card_corner_radius" card_view:cardElevation="@dimen/card_elevation" card_view:cardUseCompatPadding="true"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <LinearLayout android:id="@+id/header_container" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?attr/selectableItemBackground" android:orientation="vertical" android:paddingLeft="@dimen/card_horizontal_padding" android:paddingRight="@dimen/card_horizontal_padding"> <TextView android:id="@+id/tv_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="@dimen/card_text_small_margin" android:layout_marginTop="@dimen/card_text_big_margin" android:text="Name" android:textSize="@dimen/card_title_text_size" /> <TextView android:id="@+id/tv_subtitle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="@dimen/card_text_small_margin" android:text="Address" android:textSize="@dimen/card_subtitle_text_size" /> </LinearLayout> <com.google.android.gms.maps.MapView android:id="@+id/map_view" android:layout_width="match_parent" android:layout_height="@dimen/card_media_height" map:liteMode="true" map:mapType="none" /> <LinearLayout android:id="@+id/button_container" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:paddingBottom="@dimen/card_action_padding" android:paddingTop="@dimen/card_action_padding"> <android.support.v7.widget.AppCompatButton android:id="@+id/b_drive" style="?android:attr/borderlessButtonStyle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="@dimen/card_action_padding" android:layout_marginRight="@dimen/card_action_padding" android:minHeight="0dp" android:minWidth="0dp" android:padding="@dimen/card_action_padding" android:text="@string/card_action_drive" android:textColor="@color/color_primary" /> <android.support.v7.widget.AppCompatButton android:id="@+id/b_walk" style="?android:attr/borderlessButtonStyle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:minHeight="0dp" android:minWidth="0dp" android:padding="@dimen/card_action_padding" android:text="@string/card_action_walk" android:textColor="@color/color_primary" /> </LinearLayout> </LinearLayout> </android.support.v7.widget.CardView> 的View,但我不喜欢这个解决方案,因为我只能通过指定重叠的确切高度来使其工作查看,我希望它匹配标题和地图的高度。

String filename = ...; // code that set filename to (e.g.) rule.drl
kieFileSystem.write( "src/main/resources/" + filename, resource );

1 个答案:

答案 0 :(得分:0)

以下类是将任何叠加层置于任何视图之上的配方。 您所要做的就是将extends View替换为extends Anything,然后使用叠加层调用setOverlay(...);(在您的具体问题中为Ripple)。

所以在你的情况下它将是:

extends MapView

然后

mapView.setOverlay(mapView.getResources().getDrawable(R.drawable.ripple));

这是“食谱”类

public class PressedStateView extends View {
   public PressedStateView(Context context) {
      super(context);
   }

   public PressedStateView(Context context, AttributeSet attrs) {
      super(context, attrs);
   }

   public PressedStateView(Context context, AttributeSet attrs, int defStyleAttr) {
      super(context, attrs, defStyleAttr);
   }

   @TargetApi(Build.VERSION_CODES.LOLLIPOP)
   public PressedStateView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
      super(context, attrs, defStyleAttr, defStyleRes);
   }

   private Drawable overlay;

   public void setOverlay(Drawable overlay) {
      if (this.overlay != null) {
         this.overlay.setCallback(null);
      }
      this.overlay = overlay;
      this.overlay.setCallback(this);
      this.overlay.setBounds(0, 0, getWidth(), getHeight());
      invalidate();
   }

   @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) {
      super.onSizeChanged(w, h, oldw, oldh);
      this.overlay.setBounds(0, 0, w, h);
   }

   @Override protected boolean verifyDrawable(Drawable who) {
      return super.verifyDrawable(who) || who == overlay;
   }

   @TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override
   public void drawableHotspotChanged(float x, float y) {
      super.drawableHotspotChanged(x, y);
      if (overlay != null) {
         overlay.setHotspot(x, y);
      }
   }

   @Override protected void dispatchDraw(Canvas canvas) {
      super.dispatchDraw(canvas);
      if (overlay != null) {
         overlay.draw(canvas);
      }
   }
}