最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android自定義View實現(xiàn)箭頭沿圓轉(zhuǎn)動實例代碼

 更新時間:2017年09月28日 15:59:23   作者:zhao__na  
這篇文章主要介紹了Android自定義View實現(xiàn)箭頭沿圓轉(zhuǎn)動實例代碼,需要的朋友可以參考下

具體代碼如下所示:

//MyCircleView類
public class MyCircleView extends View{
 //當(dāng)前畫筆畫圓的顏色
 private int CurrenCircleBoundColor;
 private Paint paint;
 ////從xml中獲取的顏色
 private int circleBundColor;
 private float circleBoundWidth;
 private float pivotX;
 private float pivotY;
 private float radius=130;
 private float currentDegree=0;
 private int currentSpeed=1;
 private boolean isPause=false;
 public MyCircleView(Context context) {
  super(context);
  initView(context);
 }
 public MyCircleView(Context context, @Nullable AttributeSet attrs) {
  super(context, attrs);
  initView(context);
  TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.MyCircleView);
  for (int i = 0; i < typedArray.getIndexCount(); i++) {
   //就是我們自定義的屬性的資源id
   int attr = typedArray.getIndex(i);
   switch (attr){
    case R.styleable.MyCircleView_circlr_bound_color:
     circleBundColor = typedArray.getColor(attr, Color.RED);
     CurrenCircleBoundColor=circleBundColor;
     break;
    case R.styleable.MyCircleView_circlr_bound_width:
     circleBoundWidth = typedArray.getDimension(attr, 3);
     break;
   }
  }
 }
 public MyCircleView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
  super(context, attrs, defStyleAttr);
  initView(context);
 }
 private void initView(Context context){
  paint = new Paint();
 }
 public void setColor(int color){
  if (CurrenCircleBoundColor!=color){
   CurrenCircleBoundColor=color;
  }else {
   CurrenCircleBoundColor=circleBundColor;
  }
 }
 @Override
 protected void onDraw(Canvas canvas) {
  super.onDraw(canvas);
  paint.setAntiAlias(true);
  paint.setColor(CurrenCircleBoundColor);
  paint.setStrokeWidth(circleBoundWidth);
  paint.setStyle(Paint.Style.STROKE);
  pivotX = getWidth() / 2;
  pivotY = getHeight() / 2;
  canvas.drawCircle(pivotX,pivotY,radius,paint);
  canvas.save();
  //旋轉(zhuǎn)畫布 , 如果旋轉(zhuǎn)的的度數(shù)大的話,視覺上看著是旋轉(zhuǎn)快的
  canvas.rotate(currentDegree,pivotX,pivotY);
  //提供了一些api可以用來畫線(畫路徑)
  Path path = new Path();
  //從哪開始畫 從A開始畫
  path.moveTo(pivotX+radius,pivotY);
  //從A點畫一個直線到D點
  path.lineTo(pivotX+radius-20,pivotY-20);
  //從D點畫一個直線到B點
  path.lineTo(pivotX+radius,pivotY+20);
  //從B點畫一個直線到C點
  path.lineTo(pivotX+radius+20,pivotY-20);
  //閉合 -- 從C點畫一個直線到A點
  path.close();
  paint.setStyle(Paint.Style.FILL);
  paint.setColor(Color.BLACK);
  canvas.drawPath(path,paint);
  canvas.restore();
  //旋轉(zhuǎn)的度數(shù)一個一個度數(shù)增加, 如果乘以一個速度的話,按一個速度速度增加
  currentDegree+=1*currentSpeed;
  if (!isPause){
   invalidate();
  }
 }
 public void speed(){
  ++currentSpeed;
  if (currentSpeed>=10){
   currentSpeed=10;
   Toast.makeText(getContext(),"我比閃電還快",Toast.LENGTH_SHORT).show();
  }
 }
 public void slowDown(){
  --currentSpeed;
  if (currentSpeed<=1){
   currentSpeed=1;
  }
 }
 public void pauseOrStart(){
  //如果是開始狀態(tài)的話去重新繪制
  if (isPause){
   isPause=!isPause;
   invalidate();
  }else {
   isPause=!isPause;
  }
 }
}
//主頁面
public class MainActivity extends AppCompatActivity {
 //全局變量
 private MyCircleView my_view;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  //找控件
  my_view = (MyCircleView) findViewById(R.id.my_view);
 }
 public void onClick(View view){
  my_view.setColor(Color.BLUE);
 }
 public void add(View view){
  my_view.speed();
 }
 public void slow(View view){
  my_view.slowDown();
 }
 public void pauseOrStart(View view){
  my_view.pauseOrStart();
 }
}
主頁面布局
<RelativeLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 xmlns:app="http://schemas.android.com/apk/res-auto"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 tools:context="com.example.lx_20170928.MainActivity">
 <Button
  android:id="@+id/set_color_btn"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:layout_centerHorizontal="true"
  android:onClick="onClick"
  android:text="設(shè)置顏色" />
 <Button
  android:id="@+id/add"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:layout_below="@id/set_color_btn"
  android:layout_centerHorizontal="true"
  android:onClick="add"
  android:text="加速" />
 <Button
  android:id="@+id/slow"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:layout_below="@+id/add"
  android:layout_centerHorizontal="true"
  android:onClick="slow"
  android:text="減速" />
 <Button
  android:id="@+id/pause_or_start"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:layout_below="@+id/slow"
  android:layout_centerHorizontal="true"
  android:onClick="pauseOrStart"
  android:text="暫定/開始" />
  <com.example.lx_20170928.MyCircleView
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:id="@+id/my_view"
   android:layout_centerInParent="true"
   app:circlr_bound_color="@color/colorAccent"
   app:circlr_bound_width="3dp"
   />
</RelativeLayout>
//在values建一個attrs.xml
<resources>
 <declare-styleable name="MyCustomCircleArrowView">
  <attr name="circlr_bound_width" format="dimension"></attr>
  <attr name="circlr_bound_color" format="color"></attr>
 </declare-styleable>
</resources>

效果圖如下所示:

總結(jié)

以上所述是小編給大家介紹的Android自定義View實現(xiàn)箭頭沿圓轉(zhuǎn)動實例代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

  • Android實用的Toast工具類封裝

    Android實用的Toast工具類封裝

    這篇文章主要為大家詳細(xì)介紹了Android實用Toast工具類的封裝,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-08-08
  • Android自定義控件實現(xiàn)萬能的對話框

    Android自定義控件實現(xiàn)萬能的對話框

    這篇文章主要為大家詳細(xì)介紹了Android自定義控件實現(xiàn)萬能對話框的相關(guān)資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-03-03
  • Android?AIDL通信DeadObjectException解決方法示例

    Android?AIDL通信DeadObjectException解決方法示例

    這篇文章主要為大家介紹了Android?AIDL通信DeadObjectException解決的方法示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-03-03
  • flutter局部刷新的實現(xiàn)示例

    flutter局部刷新的實現(xiàn)示例

    這篇文章主要介紹了flutter局部刷新的實現(xiàn)示例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-09-09
  • Android仿京東金融首頁頭像效果

    Android仿京東金融首頁頭像效果

    這篇文章主要為大家詳細(xì)介紹了Android 仿京東金融首頁頭像效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-02-02
  • Android自定義View實現(xiàn)動畫效果詳解

    Android自定義View實現(xiàn)動畫效果詳解

    這篇文章主要為大家詳細(xì)介紹了Android如何通過自定義View實現(xiàn)動畫效果,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2023-02-02
  • Android調(diào)用系統(tǒng)拍照裁剪圖片模糊的解決方法

    Android調(diào)用系統(tǒng)拍照裁剪圖片模糊的解決方法

    這篇文章主要為大家詳細(xì)介紹了Android調(diào)用系統(tǒng)拍照裁剪圖片模糊的解決方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-01-01
  • Android開發(fā)人臉識別登錄功能

    Android開發(fā)人臉識別登錄功能

    這篇文章主要介紹了Android開發(fā)人臉識別登錄功能,這個很多公司都在使用,非常流行,今天小編給大家從頭到尾做一個案例分享到腳本之家平臺,需要的朋友參考下吧
    2019-11-11
  • Android中監(jiān)聽短信的兩種方法

    Android中監(jiān)聽短信的兩種方法

    這篇文章主要介紹了Android中監(jiān)聽短信的兩種方法,本文講解了監(jiān)聽廣播、采用觀察方法,監(jiān)聽短信數(shù)據(jù)庫兩種方法,需要的朋友可以參考下
    2015-04-04
  • Adapter實現(xiàn)ListView帶多選框等狀態(tài)的自定義控件的注意事項

    Adapter實現(xiàn)ListView帶多選框等狀態(tài)的自定義控件的注意事項

    Android本身為ListView提供了幾個方便的Adapter,比如ArrayAdapter、SimpleCurrentAdapter等等,接下來介紹自定義Adapter實現(xiàn)ListView帶多選框等狀態(tài)控件的注意事項,感興趣的朋友可以詳細(xì)了解下,或許對你有所幫助
    2013-01-01

最新評論

巴青县| 临海市| 塔城市| 龙山县| 青冈县| 延庆县| 沙湾县| 泰顺县| 永吉县| 盐边县| 山东| 兰西县| 揭西县| 甘肃省| 塔河县| 丘北县| 扶余县| 宁明县| 威信县| 赣榆县| 麻江县| 泽库县| 体育| 莱芜市| 松潘县| 庆阳市| 九台市| 云霄县| 霞浦县| 海盐县| 乌审旗| 怀仁县| 阿克苏市| 高阳县| 顺义区| 房山区| 关岭| 江达县| 冷水江市| 宜城市| 金寨县|