Android popupwindow 动画 特效 案例

图:

Android popupwindow 动画 特效 案例

Android popupwindow 动画 特效 案例

Android popupwindow 动画 特效 案例

Android popupwindow 动画 特效 案例

Ok,上面的效果为POPUPWINDOW简单的实现效果,下面我就把核心代码贴出来吧,希望能对想关朋友做个参考,可以通个这个小的按列来对自己做更好的扩展:

直接贴代码了:

package com.lenovo.roll;


import java.util.ArrayList;
import Android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.Matrix;
import android.os.Bundle;
import android.text.Html;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.GridView;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;


/**
 *
 * @author jankey
 *
 */
public class RollActivity extends Activity {
private View view;
private Button btn;
private PopupWindow mPopupWindow;
private View[] btns;
private GridView mListViews;

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        btn=(Button) this.findViewById(R.id.btn);
        btn.setOnClickListener(new OnClickListener(){


@Override
public void onClick(View v) {
showPopupWindow(btn);
}
       
        });
       
        initPopupWindow(R.layout.popwindow);


    }
   
private void initPopupWindow(int resId){
LayoutInflater mLayoutInflater = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
   view = mLayoutInflater.inflate(resId, null);
      
mPopupWindow = new PopupWindow(view, 400,LayoutParams.WRAP_CONTENT);
mPopupWindow.setBackgroundDrawable(getResources().getDrawable(R.drawable.bg_frame));
mPopupWindow.setOutsideTouchable(true);

mPopupWindow.setAnimationStyle(R.style.PopupAnimation);
mPopupWindow.setAnimationStyle(android.R.style.Animation_Dialog);
mPopupWindow.update();
mPopupWindow.setTouchable(true);
mPopupWindow.setFocusable(true);

btns=new View[4];
btns[0]=view.findViewById(R.id.btn_0);
btns[1]=view.findViewById(R.id.btn_1);
btns[2]=view.findViewById(R.id.btn_2);
mListViews = (GridView) view.findViewById(R.id.listViews);

String str="这只是测试,但是这是可以运用在项目中的,你需要仔细参看";
SpannableStringBuilder stryle = new SpannableStringBuilder(str);
stryle.setSpan(new ForegroundColorSpan(Color.BLUE), 0, 4, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
stryle.setSpan(new ForegroundColorSpan(Color.RED), 4, 11, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
stryle.setSpan(new ForegroundColorSpan(Color.WHITE), 11, 15, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
ArrayList<Beans> arrs = new ArrayList<Beans>();
Beans b = new Beans();
for (int i = 0; i < 20; i++) {
b.setId(R.drawable.home_light);
b.setName(stryle+"this is title");
b.setStrs("this is content!");
arrs.add(b);
}
mListViews.setAdapter(new PopAdapter(this,arrs));
btns[0].setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
ArrayList<Beans> arrs = new ArrayList<Beans>();
Beans b = new Beans();
for (int i = 0; i < 20; i++) {
b.setId(R.drawable.home_light);
b.setName("this is title");
b.setStrs("this.is content!");
arrs.add(b);
}
mListViews.setAdapter(new PopAdapter(RollActivity.this,arrs));
mListViews.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Toast.makeText(RollActivity.this,view.getId()+" <: "+position,1).show();
}
});
}
});
btns[1].setOnClickListener(new OnClickListener() {

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wwgppj.html