Android 实现旋转键盘的例子

本文通过实例代码介绍了Android中如何实现旋转键盘的功能,包括关键类DJItemImageView、DJRotateRelativeLayout和DJRotateMenuView的详细讲解,配合示例图展示了旋转键盘的效果。
摘要由CSDN通过智能技术生成



效果图



单个图片的类

DJItemImageView.java

package com.ldci.djrotatemenuforandroid;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;


public class DJItemImageView extends RelativeLayout implements OnClickListener{

	public ImageView imageView;
	
	public DJItemImageView(Context context) {
		super(context);
		//this.setBackgroundColor(Color.GREEN);

		
		
		//设置该布局的属性
		RelativeLayout.LayoutParams lp1 = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
		lp1.addRule(RelativeLayout.CENTER_HORIZONTAL);
		lp1.addRule(RelativeLayout.CENTER_VERTICAL);
	
		
		
		// TODO Auto-generated constructor stub
		imageView = new ImageView(context);
		imageView.setRotation(180);
		
		
		Bitmap bitmap = ((BitmapDrawable)getResources().getDrawable(R.drawable.ui_navi_course_in)).getBitmap();
		
		//设置图片的属性
		RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(bitmap.getWidth(), bitmap.getHeight());
		//RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		
	
		lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
		
		lp.addRule(RelativeLayout.CENTER_VERTICAL);
		
		
		imageView.setLayoutParams(lp);
		
		//imageView.setImageBitmap(bitmap);
		
		imageView.setOnClickListener(this);
		

		this.addView(imageView);
		
	//	lp1.width = bitmap.getWidth() * 3;
	//	lp1.height = bitmap.getHeight();
		this.setLayoutParams(lp1);


		
	}

	
	
	
	public void setImageTag(int tagId) {
		imageView.setId(tagId);
		Log.i("image", "imageItem tag" + tagId);
	}
	
	
	
	
	
	public void djsetImageResources(int imageId) {
		Bitmap bitmap = ((BitmapDrawable)getResources().getDrawable(imageId)).getBitmap();
		imageView.setImageBitmap(bitmap);
		
	}
	
	
	
	
	
	@Override
	public void onClick(View v) {
		
		Log.i("image", "1111111111111111111111111111" + v.getId());
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case 1001:
			Log.i("image", "1111111111111111111111111111");
			break;

		case 1002:
			Log.i("image", "222222222222222222222222222222");
			break;
		case 1003:
			Log.i("image", "33333333333333333333333333333");
			break;
			
		case 1004:
			Log.i("image", "444444444444444444444444444");
			break;
			
		case 1005:
			Log.i("image", "5555555555555555555555555555");
			break;
			
		case 1006:
			Log.i("image", "66666666666666666666666666");
			break;
			
		case 10000:
			Log.i("image", "777777777777777777777");
			break;
			
			
			
		default:
			break;
		}
		
	}
	

}


6个图片的第一次集合类

DJRotateRelativeLayout.java

package com.ldci.djrotatemenuforandroid;

import java.util.ArrayList;

import android.R.integer;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;

public class DJRotateRelativeLayout extends RelativeLayout{

	private int imageIdsDefault[] = {R.drawable.ui_navi_home,R.drawable.ui_navi_feature,R.drawable.ui_navi_course,R.drawable.ui_navi_listen,R.drawable.ui_navi_play,R.drawable.ui_navi_more};
	
	
	
	private int imageIdsIn[] = {R.drawable.ui_navi_home_in,R.drawable.ui_navi_feature_in,R.drawable.ui_navi_course_in,R.drawable.ui_navi_listen_in,R.drawable.ui_navi_play_in,R.drawable.ui_navi_more_in};
	
	private ArrayList<DJItemImageView> djArrayList;
	
	

	
	
	public DJRotateRelativeLayout(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
		//初始化一个数字
		djArrayList = new ArrayList<DJItemImageView>();
		

		
		
		this.setBackgroundColor(Color.TRANSPARENT);
		
RelativeLayout.LayoutParams bglp = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
		
		bglp.addRule(RelativeLayout.CENTER_HORIZONTAL);
		bglp.addRule(RelativeLayout.CENTER_VERTICAL);
		this.setLayoutParams(bglp);
		//this.setOnTouchListener(this);
		
		ImageView bgIma
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

杜甲同学

感谢打赏,我会继续努力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值