Android系列實現一個自定義相機的界面

      網友投稿 778 2022-05-30

      我們先實現拍照按鈕的圓形效果哈,Android開發中,當然可以找美工人員設計圖片,然后直接拿進來,不過我們可以自己寫代碼實現這個效果哈,最常用的的是用layout-list實現圖片的疊加,我們這個layout命名為btn_take_photo.xml,這是一個自定義的drawable文件,所以按照規范,我們要將它放在drawable文件夾里

      注意:drawable文件夾一般是來放自定義的drawable文件的,可以將它看成自己寫的背景樣式等等哦

      解釋代碼:

      layer-list里面放3個item,先實現一個白色背景的橢圓,屬性android:shape="oval"是實現橢圓的

      android:shape=["rectangle" | "oval" | "line" | "ring"]

      shape的形狀,默認為矩形,可以設置為矩形(rectangle)、橢圓形(oval)、線性形狀(line)、環形(ring)

      然后再放入一個item,這個item是一個左右上下都等長的橢圓

      ok,這樣一個等邊的橢圓就做好了

      接著再次放入一個一個藍色背景的橢圓

      android:bottom="6dp"

      android:left="6dp"

      android:right="6dp"

      android:top="6dp">

      android:width="1dp"

      android:color="@color/blue"

      android:dashWidth="0dp" />

      這是一個界面:activity_take_photo.xml

      界面的很簡單,這里只是提供參考學習的,解釋代碼:

      SurfaceView是用來拍照用的,注意這個類只要和視頻或者拍照的都需要用到,不過項目里一般都是自己寫的

      這些代碼只是參考互相學習,功能的話,自己還在做,所以先提供這些學習的...,希望可以幫助學習的人,然后自己寫博客的目的也是對自己學習的技術進行收錄和共享,只是本著互相學習的目的

      android:layout_width="match_parent"

      android:layout_height="match_parent"

      android:background="#ffffff">

      android:id="@+id/surfaceView"

      android:layout_width="match_parent"

      android:layout_height="match_parent" />

      android:id="@+id/buttonLayout"

      android:layout_width="match_parent"

      android:layout_height="match_parent"

      android:background="@drawable/pic">

      android:id="@+id/panel_take_photo"

      android:layout_width="fill_parent"

      android:layout_height="wrap_content"

      android:layout_alignParentBottom="true"

      android:background="@color/white"

      android:gravity="center_vertical"

      android:padding="2dp">

      android:id="@+id/btn_take_photo"

      android:layout_width="50dp"

      android:layout_height="50dp"

      android:background="@drawable/btn_take_photo"

      android:layout_centerHorizontal="true"

      android:layout_alignTop="@+id/iv_album" />

      android:id="@+id/iv_album"

      android:layout_width="40dp"

      android:layout_height="40dp"

      android:layout_alignParentLeft="true"

      android:layout_centerVertical="true"

      android:layout_marginLeft="20dp"

      android:padding="5dp"

      android:src="http://m.bai1xia.com/news/zb_users/upload/2022/05/20220530104519_96072."

      android:layout_height="40dp"

      android:layout_alignParentRight="true"

      android:layout_centerVertical="true"

      android:layout_marginRight="20dp"

      android:padding="5dp"

      android:src="@drawable/camera_back" />

      android:id="@+id/photo_area"

      android:layout_width="fill_parent"

      android:layout_height="wrap_content"

      android:layout_above="@id/panel_take_photo"

      android:layout_centerVertical="true"

      android:background="@color/white"

      android:orientation="horizontal">

      android:id="@+id/camera_top"

      android:layout_width="fill_parent"

      android:layout_height="40dp"

      android:layout_alignParentTop="true"

      android:background="@color/black">

      android:id="@+id/btn_black"

      android:layout_width="wrap_content"

      android:layout_height="fill_parent"

      android:layout_alignParentLeft="true"

      android:paddingBottom="10dp"

      android:paddingLeft="10dp"

      android:paddingTop="10dp"

      android:src="http://m.bai1xia.com/news/zb_users/upload/2022/05/20220530104519_88178."

      android:paddingRight="10dp"

      android:paddingTop="10dp"

      android:src="@drawable/camera_flip" />

      android:id="@+id/masking"

      android:layout_width="match_parent"

      android:layout_height="match_parent"

      android:layout_above="@id/photo_area"

      android:layout_alignParentTop="true" />

      android:id="@+id/focus_index"

      android:layout_width="40dp"

      android:layout_height="40dp"

      android:layout_above="@id/photo_area"

      android:background="@drawable/cam_focus"

      android:visibility="invisible" />

      提供自定義CameraGrid類:

      /**

      * 自定義的View

      * 照相機井字線

      *

      */

      public class CameraGrid extends View {

      private int topBannerWidth = 0;

      private Paint mPaint;

      public CameraGrid(Context context) {

      this(context,null);

      }

      public CameraGrid(Context context, AttributeSet attrs) {

      super(context, attrs);

      init();

      }

      Android系列之實現一個自定義相機的界面

      private void init(){

      mPaint = new Paint();

      mPaint.setColor(Color.WHITE);

      mPaint.setAlpha(120);

      mPaint.setStrokeWidth(1f);

      }

      private boolean showGrid = true;

      public boolean isShowGrid() {

      return showGrid;

      }

      public void setShowGrid(boolean showGrid) {

      this.showGrid = showGrid;

      }

      public int getTopWidth() {

      return topBannerWidth;

      }

      }

      Android

      版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。

      上一篇:又一年,畢業季,堅持學習甜蜜蜜~
      下一篇:為什么瀏覽器會提示網站“不安全”?一文讀懂https協議與SSL證書
      相關文章
      亚洲av成人无码网站…| 亚洲激情在线观看| 久久久久久亚洲精品成人| 亚洲日韩精品射精日| 亚洲视频在线免费| 伊人久久亚洲综合影院| 亚洲日韩VA无码中文字幕 | 亚洲精品乱码久久久久66| 伊人久久亚洲综合影院| 亚洲国产精品人久久电影| 国产亚洲精品成人a v小说| 午夜亚洲国产成人不卡在线| 国产精品自拍亚洲| xvideos亚洲永久网址| 亚洲?V无码乱码国产精品| 免费亚洲视频在线观看| jizzjizz亚洲| 亚洲日韩国产一区二区三区| 亚洲中文字幕丝袜制服一区| 中文字幕亚洲日韩无线码| 国产亚洲精品AA片在线观看不加载 | mm1313亚洲国产精品无码试看| 亚洲变态另类一区二区三区| 亚洲av片在线观看| 国产偷国产偷亚洲高清在线| 亚洲精品国产日韩无码AV永久免费网 | 亚洲av成人无码久久精品| 亚洲福利视频导航| 亚洲综合久久久久久中文字幕| 亚洲欧洲日产国产最新| 亚洲AV无码一区二区三区人| 亚洲AV无码无限在线观看不卡| 亚洲乱人伦中文字幕无码| 另类图片亚洲校园小说区| 亚洲午夜精品第一区二区8050| 亚洲中文字幕无码日韩| 亚洲嫩草影院久久精品| 亚洲制服丝袜在线播放| 亚洲精品综合在线影院| 亚洲JIZZJIZZ妇女| 亚洲中文字幕视频国产|