我的编程空间,编程开发者的网络收藏夹
学习永远不晚

基于Android实现转盘按钮代码

短信预约 -IT技能 免费直播动态提醒
省份

北京

  • 北京
  • 上海
  • 天津
  • 重庆
  • 河北
  • 山东
  • 辽宁
  • 黑龙江
  • 吉林
  • 甘肃
  • 青海
  • 河南
  • 江苏
  • 湖北
  • 湖南
  • 江西
  • 浙江
  • 广东
  • 云南
  • 福建
  • 海南
  • 山西
  • 四川
  • 陕西
  • 贵州
  • 安徽
  • 广西
  • 内蒙
  • 西藏
  • 新疆
  • 宁夏
  • 兵团
手机号立即预约

请填写图片验证码后获取短信验证码

看不清楚,换张图片

免费获取短信验证码

基于Android实现转盘按钮代码

先给大家展示下效果图:


package com.lixu.circlemenu;
 import android.app.Activity;
 import android.os.Bundle;
 import android.view.View;
 import android.widget.TextView;
 import android.widget.Toast;
 import com.lixu.circlemenu.view.CircleImageView;
 import com.lixu.circlemenu.view.CircleLayout;
 import com.lixu.circlemenu.view.CircleLayout.OnItemClickListener;
 import com.lixu.circlemenu.view.CircleLayout.OnItemSelectedListener;
 import com.szugyi.circlemenu.R;
 public class MainActivity extends Activity implements OnItemSelectedListener, OnItemClickListener{
   private  TextView selectedTextView;
   @Override
   protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.activity_main);
     CircleLayout circleMenu = (CircleLayout)findViewById(R.id.main_circle_layout);
     circleMenu.setOnItemSelectedListener(this);
     circleMenu.setOnItemClickListener(this);
     //这个TextView仅仅作为演示转盘按钮以何为默认的选中项,
     //默认的最底部的那一条被选中,然后显示到该TextView中。
     selectedTextView = (TextView)findViewById(R.id.main_selected_textView);
     selectedTextView.setText(((CircleImageView)circleMenu.getSelectedItem()).getName());
   }
   //圆盘转动到底部,则认为该条目被选中
   @Override
   public void onItemSelected(View view, int position, long id, String name) {    
     selectedTextView.setText(name);
   }
   //选择了转盘中的某一条。
   @Override
   public void onItemClick(View view, int position, long id, String name) {
     Toast.makeText(getApplicationContext(), getResources().getString(R.string.start_app) + " " + name, Toast.LENGTH_SHORT).show();
   }
 }

引用两个开源类:


 package com.lixu.circlemenu.view;
 
 import android.content.Context;
 import android.content.res.TypedArray;
 import android.util.AttributeSet;
 import android.widget.ImageView;
 import com.szugyi.circlemenu.R;
 
 public class CircleImageView extends ImageView {
   private float angle = ;
   private int position = ;
   private String name;
   public float getAngle() {
     return angle;
   }
   public void setAngle(float angle) {
     this.angle = angle;
   }
   public int getPosition() {
     return position;
   }
   public void setPosition(int position) {
     this.position = position;
   }
   public String getName(){
     return name;
   }
   public void setName(String name){
     this.name = name;
   }
   
   public CircleImageView(Context context) {
     this(context, null);
   }
   
   public CircleImageView(Context context, AttributeSet attrs) {
     this(context, attrs, );
   }
   
   public CircleImageView(Context context, AttributeSet attrs, int defStyle) {
     super(context, attrs, defStyle);
     if (attrs != null) {
       TypedArray a = getContext().obtainStyledAttributes(attrs,
           R.styleable.CircleImageView);
       name = a.getString(R.styleable.CircleImageView_name);
     }
   }
 }
  package com.lixu.circlemenu.view;
  import com.szugyi.circlemenu.R;
  
 import android.content.Context;
 import android.content.res.TypedArray;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
 import android.graphics.Canvas;
 import android.graphics.Matrix;
 import android.util.AttributeSet;
 import android.view.GestureDetector;
 import android.view.GestureDetector.SimpleOnGestureListener;
 import android.view.MotionEvent;
 import android.view.View;
 import android.view.ViewGroup;
 
 public class CircleLayout extends ViewGroup {
   // Event listeners
   private OnItemClickListener mOnItemClickListener = null;
   private OnItemSelectedListener mOnItemSelectedListener = null;
   private OnCenterClickListener mOnCenterClickListener = null;
   // Background image
   private Bitmap imageOriginal, imageScaled;
   private Matrix matrix;
   private int mTappedViewsPostition = -;
   private View mTappedView = null;
   private int selected = ;
   // Child sizes
   private int mMaxChildWidth = ;
   private int mMaxChildHeight = ;
   private int childWidth = ;
   private int childHeight = ;
   // Sizes of the ViewGroup
   private int circleWidth, circleHeight;
   private int radius = ;
   // Touch detection
   private GestureDetector mGestureDetector;
   // needed for detecting the inversed rotations
   private boolean[] quadrantTouched;
   // Settings of the ViewGroup
   private boolean allowRotating = true;
   private float angle = ;
   private float firstChildPos = ;
   private boolean rotateToCenter = true;
   private boolean isRotating = true;
   
   public CircleLayout(Context context) {
     this(context, null);
   }
   
   public CircleLayout(Context context, AttributeSet attrs) {
     this(context, attrs, );
   }
   
   public CircleLayout(Context context, AttributeSet attrs, int defStyle) {
     super(context, attrs, defStyle);
     init(attrs);
   }
   
   protected void init(AttributeSet attrs) {
     mGestureDetector = new GestureDetector(getContext(),
         new MyGestureListener());
     quadrantTouched = new boolean[] { false, false, false, false, false };
     if (attrs != null) {
       TypedArray a = getContext().obtainStyledAttributes(attrs,
           R.styleable.Circle);
       // The angle where the first menu item will be drawn
       angle = a.getInt(R.styleable.Circle_firstChildPosition, );
       firstChildPos = angle;
       rotateToCenter = a.getBoolean(R.styleable.Circle_rotateToCenter,
           true);      
       isRotating = a.getBoolean(R.styleable.Circle_isRotating, true);
       // If the menu is not rotating then it does not have to be centered
       // since it cannot be even moved
       if (!isRotating) {
         rotateToCenter = false;
       }
       if (imageOriginal == null) {
         int picId = a.getResourceId(
             R.styleable.Circle_circleBackground, -);
         // If a background image was set as an attribute, 
         // retrieve the image
         if (picId != -) {
           imageOriginal = BitmapFactory.decodeResource(
               getResources(), picId);
         }
       }
       a.recycle();
       // initialize the matrix only once
       if (matrix == null) {
         matrix = new Matrix();
       } else {
         // not needed, you can also post the matrix immediately to
         // restore the old state
         matrix.reset();
       }
       // Needed for the ViewGroup to be drawn
       setWillNotDraw(false);
     }
   }
   
   public View getSelectedItem() {
     return (selected >= ) ? getChildAt(selected) : null;
   }
   @Override
   protected void onDraw(Canvas canvas) {
     // the sizes of the ViewGroup
     circleHeight = getHeight();
     circleWidth = getWidth();
     if (imageOriginal != null) {
       // Scaling the size of the background image
       if (imageScaled == null) {
         matrix = new Matrix();
         float sx = (((radius + childWidth / ) * ) / (float) imageOriginal
             .getWidth());
         float sy = (((radius + childWidth / ) * ) / (float) imageOriginal
             .getHeight());
         matrix.postScale(sx, sy);
         imageScaled = Bitmap.createBitmap(imageOriginal, , ,
             imageOriginal.getWidth(), imageOriginal.getHeight(),
             matrix, false);
       }
       if (imageScaled != null) {
         // Move the background to the center
         int cx = (circleWidth - imageScaled.getWidth()) / ;
         int cy = (circleHeight - imageScaled.getHeight()) / ;
         Canvas g = canvas;
         canvas.rotate(, circleWidth / , circleHeight / );
         g.drawBitmap(imageScaled, cx, cy, null);
       }
     }
   }
   @Override
   protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
     mMaxChildWidth = ;
     mMaxChildHeight = ;
     // Measure once to find the maximum child size.
     int childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(
         MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.AT_MOST);
     int childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(
         MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.AT_MOST);
     final int count = getChildCount();
     for (int i = ; i < count; i++) {
       final View child = getChildAt(i);
       if (child.getVisibility() == GONE) {
         continue;
       }
       child.measure(childWidthMeasureSpec, childHeightMeasureSpec);
       mMaxChildWidth = Math.max(mMaxChildWidth, child.getMeasuredWidth());
       mMaxChildHeight = Math.max(mMaxChildHeight,
           child.getMeasuredHeight());
     }
     // Measure again for each child to be exactly the same size.
     childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(mMaxChildWidth,
         MeasureSpec.EXACTLY);
     childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(mMaxChildHeight,
         MeasureSpec.EXACTLY);
     for (int i = ; i < count; i++) {
       final View child = getChildAt(i);
       if (child.getVisibility() == GONE) {
         continue;
       }
       child.measure(childWidthMeasureSpec, childHeightMeasureSpec);
     }
     setMeasuredDimension(resolveSize(mMaxChildWidth, widthMeasureSpec),
         resolveSize(mMaxChildHeight, heightMeasureSpec));
   }
   @Override
   protected void onLayout(boolean changed, int l, int t, int r, int b) {
     int layoutWidth = r - l;
     int layoutHeight = b - t;
     // Laying out the child views
     final int childCount = getChildCount();
     int left, top;
     radius = (layoutWidth <= layoutHeight) ? layoutWidth / 
         : layoutHeight / ;
     childWidth = (int) (radius / .);
     childHeight = (int) (radius / .);
     float angleDelay = / getChildCount();
     for (int i = ; i < childCount; i++) {
       final CircleImageView child = (CircleImageView) getChildAt(i);
       if (child.getVisibility() == GONE) {
         continue;
       }
       if (angle > ) {
         angle -= ;
       } else {
         if (angle < ) {
           angle += ;
         }
       }
       child.setAngle(angle);
       child.setPosition(i);
       left = Math
           .round((float) (((layoutWidth / ) - childWidth / ) + radius
               * Math.cos(Math.toRadians(angle))));
       top = Math
           .round((float) (((layoutHeight / ) - childHeight / ) + radius
               * Math.sin(Math.toRadians(angle))));
       child.layout(left, top, left + childWidth, top + childHeight);
       angle += angleDelay;
     }
   }
   
   private void rotateButtons(float degrees) {
     int left, top, childCount = getChildCount();
     float angleDelay = / childCount;
     angle += degrees;
     if (angle > ) {
       angle -= ;
     } else {
       if (angle < ) {
         angle += ;
       }
     }
     for (int i = ; i < childCount; i++) {
       if (angle > ) {
         angle -= ;
       } else {
         if (angle < ) {
           angle += ;
         }
       }
       final CircleImageView child = (CircleImageView) getChildAt(i);
       if (child.getVisibility() == GONE) {
         continue;
       }
       left = Math
           .round((float) (((circleWidth / ) - childWidth / ) + radius
               * Math.cos(Math.toRadians(angle))));
       top = Math
           .round((float) (((circleHeight / ) - childHeight / ) + radius
               * Math.sin(Math.toRadians(angle))));
       child.setAngle(angle);
       if (Math.abs(angle - firstChildPos) < (angleDelay / )
           && selected != child.getPosition()) {
         selected = child.getPosition();
         if (mOnItemSelectedListener != null && rotateToCenter) {
           mOnItemSelectedListener.onItemSelected(child, selected,
               child.getId(), child.getName());
         }
       }
       child.layout(left, top, left + childWidth, top + childHeight);
       angle += angleDelay;
     }
   }
   
   private double getAngle(double xTouch, double yTouch) {
     double x = xTouch - (circleWidth / d);
     double y = circleHeight - yTouch - (circleHeight / d);
     switch (getQuadrant(x, y)) {
     case :
       return Math.asin(y / Math.hypot(x, y)) * / Math.PI;
     case :
     case :
       return - (Math.asin(y / Math.hypot(x, y)) * / Math.PI);
     case :
       return + Math.asin(y / Math.hypot(x, y)) * / Math.PI;
     default:
       // ignore, does not happen
       return ;
     }
   }
   
   private static int getQuadrant(double x, double y) {
     if (x >= ) {
       return y >= ? : ;
     } else {
       return y >= ? : ;
     }
   }
   private double startAngle;
   @Override
   public boolean onTouchEvent(MotionEvent event) {
     if (isEnabled()) {
       if (isRotating) {
         switch (event.getAction()) {
         case MotionEvent.ACTION_DOWN:
           // reset the touched quadrants
           for (int i = ; i < quadrantTouched.length; i++) {
             quadrantTouched[i] = false;
           }
           allowRotating = false;
           startAngle = getAngle(event.getX(), event.getY());
           break;
         case MotionEvent.ACTION_MOVE:
           double currentAngle = getAngle(event.getX(), event.getY());
           rotateButtons((float) (startAngle - currentAngle));
           startAngle = currentAngle;
           break;
         case MotionEvent.ACTION_UP:
           allowRotating = true;
           rotateViewToCenter((CircleImageView) getChildAt(selected),
               false);
           break;
         }
       }
       // set the touched quadrant to true
       quadrantTouched[getQuadrant(event.getX() - (circleWidth / ),
           circleHeight - event.getY() - (circleHeight / ))] = true;
       mGestureDetector.onTouchEvent(event);
       return true;
     }
     return false;
   }
   private class MyGestureListener extends SimpleOnGestureListener {
     @Override
     public boolean onFling(MotionEvent e, MotionEvent e, float velocityX,
         float velocityY) {
       if (!isRotating) {
         return false;
       }
       // get the quadrant of the start and the end of the fling
       int q = getQuadrant(e.getX() - (circleWidth / ), circleHeight
           - e.getY() - (circleHeight / ));
       int q = getQuadrant(e.getX() - (circleWidth / ), circleHeight
           - e.getY() - (circleHeight / ));
       // the inversed rotations
       if ((q == && q == && Math.abs(velocityX) < Math
           .abs(velocityY))
           || (q == && q == )
           || (q == && q == )
           || (q == && q == && Math.abs(velocityX) > Math
               .abs(velocityY))
           || ((q == && q == ) || (q == && q == ))
           || ((q == && q == ) || (q == && q == ))
           || (q == && q == && quadrantTouched[])
           || (q == && q == && quadrantTouched[])) {
         CircleLayout.this.post(new FlingRunnable(-
             * (velocityX + velocityY)));
       } else {
         // the normal rotation
         CircleLayout.this
             .post(new FlingRunnable(velocityX + velocityY));
       }
       return true;
     }
     @Override
     public boolean onSingleTapUp(MotionEvent e) {
       mTappedViewsPostition = pointToPosition(e.getX(), e.getY());
       if (mTappedViewsPostition >= ) {
         mTappedView = getChildAt(mTappedViewsPostition);
         mTappedView.setPressed(true);
       } else {
         float centerX = circleWidth / ;
         float centerY = circleHeight / ;
         if (e.getX() < centerX + (childWidth / )
             && e.getX() > centerX - childWidth / 
             && e.getY() < centerY + (childHeight / )
             && e.getY() > centerY - (childHeight / )) {
           if (mOnCenterClickListener != null) {
             mOnCenterClickListener.onCenterClick();
             return true;
           }
         }
       }
       if (mTappedView != null) {
         CircleImageView view = (CircleImageView) (mTappedView);
         if (selected != mTappedViewsPostition) {
           rotateViewToCenter(view, false);
           if (!rotateToCenter) {
             if (mOnItemSelectedListener != null) {
               mOnItemSelectedListener.onItemSelected(mTappedView,
                   mTappedViewsPostition, mTappedView.getId(), view.getName());
             }
             if (mOnItemClickListener != null) {
               mOnItemClickListener.onItemClick(mTappedView,
                   mTappedViewsPostition, mTappedView.getId(), view.getName());
             }
           }
         } else {
           rotateViewToCenter(view, false);
           if (mOnItemClickListener != null) {
             mOnItemClickListener.onItemClick(mTappedView,
                 mTappedViewsPostition, mTappedView.getId(), view.getName());
           }
         }
         return true;
       }
       return super.onSingleTapUp(e);
     }
   }
   
   private void rotateViewToCenter(CircleImageView view, boolean fromRunnable) {
     if (rotateToCenter) {
       float velocityTemp = ;
       float destAngle = (float) (firstChildPos - view.getAngle());
       float startAngle = ;
       int reverser = ;
       if (destAngle < ) {
         destAngle += ;
       }
       if (destAngle > ) {
         reverser = -;
         destAngle = - destAngle;
       }
       while (startAngle < destAngle) {
         startAngle += velocityTemp / ;
         velocityTemp *= .F;
       }
       CircleLayout.this.post(new FlingRunnable(reverser * velocityTemp,
           !fromRunnable));
     }
   }
   
   private class FlingRunnable implements Runnable {
     private float velocity;
     float angleDelay;
     boolean isFirstForwarding = true;
     public FlingRunnable(float velocity) {
       this(velocity, true);
     }
     public FlingRunnable(float velocity, boolean isFirst) {
       this.velocity = velocity;
       this.angleDelay = / getChildCount();
       this.isFirstForwarding = isFirst;
     }
     public void run() {
       if (Math.abs(velocity) > && allowRotating) {
         if (rotateToCenter) {
           if (!(Math.abs(velocity) < && (Math.abs(angle
               - firstChildPos)
               % angleDelay < ))) {
             rotateButtons(velocity / );
             velocity /= .F;
             CircleLayout.this.post(this);
           }
         } else {
           rotateButtons(velocity / );
           velocity /= .F;
           CircleLayout.this.post(this);
         }
       } else {
         if (isFirstForwarding) {
           isFirstForwarding = false;
           CircleLayout.this.rotateViewToCenter(
               (CircleImageView) getChildAt(selected), true);
         }
       }
     }
   }
   private int pointToPosition(float x, float y) {
     for (int i = ; i < getChildCount(); i++) {
       View item = (View) getChildAt(i);
       if (item.getLeft() < x && item.getRight() > x & item.getTop() < y
           && item.getBottom() > y) {
         return i;
       }
     }
     return -;
   }
   public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
     this.mOnItemClickListener = onItemClickListener;
   }
   public interface OnItemClickListener {
     void onItemClick(View view, int position, long id, String name);
   }
   public void setOnItemSelectedListener(
       OnItemSelectedListener onItemSelectedListener) {
     this.mOnItemSelectedListener = onItemSelectedListener;
   }
   public interface OnItemSelectedListener {
     void onItemSelected(View view, int position, long id, String name);
   }
   public interface OnCenterClickListener {
     void onCenterClick();
   }
   public void setOnCenterClickListener(
       OnCenterClickListener onCenterClickListener) {
     this.mOnCenterClickListener = onCenterClickListener;
   }
 }

xml文件:
 
  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:circle="http://schemas.android.com/apk/res/com.szugyi.circlemenu"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context=".MainActivity" >
      <com.lixu.circlemenu.view.CircleLayout
          android:id="@+id/main_circle_layout"
         android:layout_width="fill_parent"
         android:layout_height="fill_parent"
         android:layout_above="@+id/main_selected_textView"
         android:layout_gravity="center_horizontal"
         circle:firstChildPosition="South"
         circle:rotateToCenter="true"
         circle:isRotating="true" >      
 <!--         circle:circleBackground="@drawable/green"  > -->
         <com.lixu.circlemenu.view.CircleImageView
             android:id="@+id/main_facebook_image"
             android:layout_width="dp"
             android:layout_height="dp"
             android:class="lazy" data-src="@drawable/icon_facebook"
             circle:name="@string/facebook" />
         <com.lixu.circlemenu.view.CircleImageView
             android:id="@+id/main_myspace_image"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:class="lazy" data-src="@drawable/icon_myspace"
             circle:name="@string/myspace" />
         <com.lixu.circlemenu.view.CircleImageView
             android:id="@+id/main_google_image"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:class="lazy" data-src="@drawable/icon_google"
             circle:name="@string/google" />
         <com.lixu.circlemenu.view.CircleImageView
             android:id="@+id/main_linkedin_image"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:class="lazy" data-src="@drawable/icon_linkedin"
             circle:name="@string/linkedin" />
         <com.lixu.circlemenu.view.CircleImageView
             android:id="@+id/main_twitter_image"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:class="lazy" data-src="@drawable/icon_twitter"
             circle:name="@string/twitter" />
         <com.lixu.circlemenu.view.CircleImageView
             android:id="@+id/main_wordpress_image"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:class="lazy" data-src="@drawable/icon_wordpress"
             circle:name="@string/wordpress" />
     </com.lixu.circlemenu.view.CircleLayout>
     <TextView
         android:id="@+id/main_selected_textView"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_alignParentBottom="true"
         android:layout_centerHorizontal="true"
         android:layout_marginBottom="dp"
         android:textAppearance="?android:attr/textAppearanceLarge" />
 </RelativeLayout>

基于Android实现转盘按钮代码的全部内容就到此结束了,希望能够帮助到大家。

您可能感兴趣的文章:Android自定义view制作抽奖转盘Android自定义View实现抽奖转盘Android自定义View实现QQ运动积分转盘抽奖功能Android使用surfaceView自定义抽奖大转盘Android中利用SurfaceView制作抽奖转盘的全流程攻略Android实现抽奖转盘实例代码Android实现可点击的幸运大转盘


免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

基于Android实现转盘按钮代码

下载Word文档到电脑,方便收藏和打印~

下载Word文档

猜你喜欢

基于Android实现转盘按钮代码

先给大家展示下效果图:package com.lixu.circlemenu;import android.app.Activity;import android.os.Bundle;import android.view.View;imp
2022-06-06

【vscode基于clangd实现Android/Linux代码跳转】

背景: 在开发大型工程例如Android或Linux时若我们使用vscode搭配官方的C/C++插件使用发现,经常很多代码都无法跳转,代码补全功能几乎是废的,通过网友以及同事身边了解之后发现vscode+clangd可以实现代码任意跳转补全
2023-08-24

Android自定义实现开关按钮代码

我们在应用中经常看到一些选择开关状态的配置文件,做项目的时候用的是android的Switch控件,但是感觉好丑的样子子个人认为还是自定义的比较好,先上个效果图:实现过程:1.准备开关不同状态的两张图片放入drawable中。2.xml文件
2022-06-06

Android点击按钮返回顶部实现代码

点击按钮返回顶部,直接上代码吧 布局文件2022-06-06

Android中实现图文并茂的按钮实例代码

效果图如下所示:代码:
2022-06-06

Android实现倒计时的按钮的示例代码

最近有人问我如何实现倒计时的按钮功能,例如发送验证码,我记得有个CountDownTimer,因为好久没用过了,自己就写了一个,代码如下new CountDownTimer(10000, 1000) {@Overridepublic voi
2022-06-06

Android实现抽奖转盘实例代码

本文详述了android抽奖程序的实现方法,程序为一个抽奖大转盘代码,里面定义了很多图形方法和动画。 实现主要功能的SlyderView.java源代码如下:import android.app.Activity; import andro
2022-06-06

Android实现带有删除按钮的EditText示例代码

一、首先来看看效果这是一个带有删除按钮的输入文本框, 需要新建一个类继承自EditText, 先把代码贴出来, 然后在解释: 示例代码如下:public class EditTextWithDel extends EditText {pri
2022-06-06

Android实现空心圆角矩形按钮的实例代码

页面上有时会用到背景为空心圆角矩形的Button,可以通过xml绘制出来。 drawrable文件夹下bg_red_hollow_rectangle.xml
2022-06-06

基于Android代码实现常用布局

关于 android 常用布局,利用 XML 文件实现已经有很多的实例了。但如何利用代码实现呢?当然利用代码实现没有太大的必要,也是不提倡的,但我觉得利用代码实现这些布局,可以更好的了解 SDK API ,所以在此也整理一些,和大家分享一下
2022-06-06

android怎么实现点击按钮跳转页面

Android中实现点击按钮跳转页面可以通过以下步骤实现:1. 在XML布局文件中定义一个按钮组件,例如:```xmlandroid:id="@+id/button"android:layout_width="wrap_content"an
2023-08-11

基于Android实现点击某个按钮让菜单选项从按钮周围指定位置弹出

Android Material Design:PopupMenuAndroid Material Design 引入的PopupMenu类似过去的上下文菜单,但是更灵活。 如图所示:现在给出实现上图PopupMenu的代码。 本例是一个普
2022-06-06

纯CSS代码如何实现暂停按钮

这篇文章主要介绍“纯CSS代码如何实现暂停按钮”,在日常操作中,相信很多人在纯CSS代码如何实现暂停按钮问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”纯CSS代码如何实现暂停按钮”的疑惑有所帮助!接下来,请跟
2023-07-05

Android ImageButton自定义按钮的按下效果的代码实现方法分享

使用Button时为了让用户有“按下”的效果,有两种实现方式:1.在代码里面。代码如下:imageButton.setOnTouchListener(new OnTouchListener(){
2022-06-06

编程热搜

  • Android:VolumeShaper
    VolumeShaper(支持版本改一下,minsdkversion:26,android8.0(api26)进一步学习对声音的编辑,可以让音频的声音有变化的播放 VolumeShaper.Configuration的三个参数 durati
    Android:VolumeShaper
  • Android崩溃异常捕获方法
    开发中最让人头疼的是应用突然爆炸,然后跳回到桌面。而且我们常常不知道这种状况会何时出现,在应用调试阶段还好,还可以通过调试工具的日志查看错误出现在哪里。但平时使用的时候给你闹崩溃,那你就欲哭无泪了。 那么今天主要讲一下如何去捕捉系统出现的U
    Android崩溃异常捕获方法
  • android开发教程之获取power_profile.xml文件的方法(android运行时能耗值)
    系统的设置–>电池–>使用情况中,统计的能耗的使用情况也是以power_profile.xml的value作为基础参数的1、我的手机中power_profile.xml的内容: HTC t328w代码如下:
    android开发教程之获取power_profile.xml文件的方法(android运行时能耗值)
  • Android SQLite数据库基本操作方法
    程序的最主要的功能在于对数据进行操作,通过对数据进行操作来实现某个功能。而数据库就是很重要的一个方面的,Android中内置了小巧轻便,功能却很强的一个数据库–SQLite数据库。那么就来看一下在Android程序中怎么去操作SQLite数
    Android SQLite数据库基本操作方法
  • ubuntu21.04怎么创建桌面快捷图标?ubuntu软件放到桌面的技巧
    工作的时候为了方便直接打开编辑文件,一些常用的软件或者文件我们会放在桌面,但是在ubuntu20.04下直接直接拖拽文件到桌面根本没有效果,在进入桌面后发现软件列表中的软件只能收藏到面板,无法复制到桌面使用,不知道为什么会这样,似乎并不是很
    ubuntu21.04怎么创建桌面快捷图标?ubuntu软件放到桌面的技巧
  • android获取当前手机号示例程序
    代码如下: public String getLocalNumber() { TelephonyManager tManager =
    android获取当前手机号示例程序
  • Android音视频开发(三)TextureView
    简介 TextureView与SurfaceView类似,可用于显示视频或OpenGL场景。 与SurfaceView的区别 SurfaceView不能使用变换和缩放等操作,不能叠加(Overlay)两个SurfaceView。 Textu
    Android音视频开发(三)TextureView
  • android获取屏幕高度和宽度的实现方法
    本文实例讲述了android获取屏幕高度和宽度的实现方法。分享给大家供大家参考。具体分析如下: 我们需要获取Android手机或Pad的屏幕的物理尺寸,以便于界面的设计或是其他功能的实现。下面就介绍讲一讲如何获取屏幕的物理尺寸 下面的代码即
    android获取屏幕高度和宽度的实现方法
  • Android自定义popupwindow实例代码
    先来看看效果图:一、布局
  • Android第一次实验
    一、实验原理 1.1实验目标 编程实现用户名与密码的存储与调用。 1.2实验要求 设计用户登录界面、登录成功界面、用户注册界面,用户注册时,将其用户名、密码保存到SharedPreference中,登录时输入用户名、密码,读取SharedP
    Android第一次实验

目录