switch button

网友投稿 751 2022-09-06

switch button

switch button

import android.app.Activity;import android.content.Intent;import android.graphics.Bitmap;import android.util.Log;import android.view.MotionEvent;import android.view.View;import android.view.View.OnClickListener;import android.widget.ImageView;import android.widget.LinearLayout;import android.widget.ImageView.ScaleType;public class SwitchBtn extends LinearLayout implements OnClickListener{ private Activity context; public FavoritenSwitchBtn(final Activity context,int selectIndex) { super(context); this.context =context; setOrientation(LinearLayout.HORIZONTAL); LinearLayout iconLayout = new LinearLayout(context); iconLayout.setOrientation(LinearLayout.HORIZONTAL); LinearLayout.LayoutParams iconParams = new LinearLayout.LayoutParams(LayoutSize.Pl_Width,LayoutSize.Favoriten_DaoHang_Bg_Height); iconParams.setMargins(LayoutSize.Favoriten_Btn_Image_Left, LayoutSize.Favoriten_Btn_Image_Top, 0, 0); this.addView(iconLayout,iconParams); final int[][] menuIcon = new int[][]{{R.drawable.image_f,R.drawable.image_f1},{R.drawable.product_f,R.drawable.product_f1},{R.drawable.active_f,R.drawable.active_f1}}; String[] menuTag = new String[]{"t_product","t_active","t_style","t_log","t_favoriten"}; if(selectIndex>=3)selectIndex=selectIndex-1; LinearLayout.LayoutParams menuVLayout = new LinearLayout.LayoutParams(0, 0); LinearLayout.LayoutParams menuLayout = new LinearLayout.LayoutParams(LayoutSize.Favoriten_Btn_Image_Width, LayoutSize.Favoriten_Btn_Image_Height); for(int i=0;i<3;i++){ final int[] icon = menuIcon[i]; ImageView ib; if(i==selectIndex){ ib = new ImageView(context); Bitmap bitmap = Tool.getImageBitmap(icon[1], context); Bitmap bitmap2 = Tool.scaleImg(bitmap,LayoutSize.Favoriten_Btn_Image_Width, LayoutSize.Favoriten_Btn_Image_Height); ib.setImageBitmap(bitmap2); }else{ ib = new ImageView(context){ @Override public boolean onTouchEvent(MotionEvent event) { if(event.getAction() == MotionEvent.ACTION_UP){ Bitmap bitmap = Tool.getImageBitmap(icon[0], context); Bitmap bitmap2 = Tool.scaleImg(bitmap, LayoutSize.Favoriten_Btn_Image_Width, LayoutSize.Favoriten_Btn_Image_Height); setImageBitmap(bitmap2); }else if(event.getAction() == MotionEvent.ACTION_DOWN){ Bitmap bitmap = Tool.getImageBitmap(icon[1], context); Bitmap bitmap2 = Tool.scaleImg(bitmap, LayoutSize.Favoriten_Btn_Image_Width, LayoutSize.Favoriten_Btn_Image_Height); setImageBitmap(bitmap2); } return super.onTouchEvent(event); } }; Bitmap bitmap = Tool.getImageBitmap(icon[0], context); Bitmap bitmap2 = Tool.scaleImg(bitmap,LayoutSize.Favoriten_Btn_Image_Width, LayoutSize.Favoriten_Btn_Image_Height); ib.setImageBitmap(bitmap2); ib.setScaleType(ScaleType.CENTER_INSIDE); ib.setOnClickListener(this); } ib.setLayoutParams(menuLayout); ib.setTag(menuTag[i]); ib.setBackgroundDrawable(null); ib.setPadding(0, 0, 0, 0); iconLayout.addView(ib); } } @Override public void onClick(View v) { if("t_product".equals(v.getTag())){ Intent it = new Intent(); it.setClass(context, StyleFavoritenActivity.class); it.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP |Intent.FLAG_ACTIVITY_CLEAR_TOP); context.startActivity(it); }else if("t_active".equals(v.getTag())){ Intent it = new Intent(); it.setClass(context, ProductFavoritenActivity.class); it.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP |Intent.FLAG_ACTIVITY_CLEAR_TOP); context.startActivity(it); }else if("t_style".equals(v.getTag())){ Intent it = new Intent(); it.setClass(context, ActiveFavoritenActivity.class); it.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP |Intent.FLAG_ACTIVITY_CLEAR_TOP); context.startActivity(it); } }}

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:使用mysqlbinlog工具进行基于位置或时间点的数据恢复(mysql使用binlog恢复)
下一篇:Given a list of numbers ( fixed list) Now given any other list, how can you efficiently find out if
相关文章

 发表评论

暂时没有评论,来抢沙发吧~