popwindow+动画
Posted 红领巾传递人
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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;
}
}
}
以上是关于popwindow+动画的主要内容,如果未能解决你的问题,请参考以下文章