zoukankan      html  css  js  c++  java
  • popwindow+动画

    布局:

    main:

    <Button
    android:id="@+id/btn"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

    pop:

    <ImageView
    android:id="@+id/iv"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:src="@mipmap/ic_launcher"
    />

    代码:

    package com.example.my_popwindow_donghua;

    import android.os.Bundle;
    import android.support.v7.app.ActionBar;
    import android.support.v7.app.AppCompatActivity;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.animation.AlphaAnimation;
    import android.view.animation.Animation;
    import android.view.animation.AnimationUtils;
    import android.widget.Button;
    import android.widget.ImageView;
    import android.widget.PopupWindow;

    public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    private PopupWindow popupWindow;
    private Button btn;
    private ImageView iv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    initView();

    }

    private void initView() {
    btn = (Button) findViewById(R.id.btn);

    View inflate = LayoutInflater.from(this).inflate(R.layout.pop, null);
    iv = (ImageView) inflate.findViewById(R.id.iv);
    popupWindow = new PopupWindow(inflate, ActionBar.LayoutParams.WRAP_CONTENT, ActionBar.LayoutParams.WRAP_CONTENT);
    btn.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
    switch (v.getId()) {
    case R.id.btn:
    // AlphaAnimation alphaAnimation = new AlphaAnimation(1,0);

    // alphaAnimation.setDuration(2000);
    Animation alphaAnimation = AnimationUtils.loadAnimation(this,R.anim.bib);
    iv.startAnimation(alphaAnimation);

    if (popupWindow.isShowing()){

    popupWindow.dismiss();

    }else {

    popupWindow.showAsDropDown(btn);
    }

    break;
    }
    }
    }
  • 相关阅读:
    LeetCode Count of Range Sum
    LeetCode 158. Read N Characters Given Read4 II
    LeetCode 157. Read N Characters Given Read4
    LeetCode 317. Shortest Distance from All Buildings
    LeetCode Smallest Rectangle Enclosing Black Pixels
    LeetCode 315. Count of Smaller Numbers After Self
    LeetCode 332. Reconstruct Itinerary
    LeetCode 310. Minimum Height Trees
    LeetCode 163. Missing Ranges
    LeetCode Verify Preorder Serialization of a Binary Tree
  • 原文地址:https://www.cnblogs.com/98k98k/p/7822681.html
Copyright © 2011-2022 走看看