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

Android自定義相機界面的實現(xiàn)代碼

 更新時間:2022年05月19日 09:08:09   作者:u014427391  
這篇文章主要為大家詳細介紹了Android自定義相機界面的實現(xiàn)代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下

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

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

解釋代碼:

layer-list里面放3個item,先實現(xiàn)一個白色背景的橢圓,屬性android:shape="oval"是實現(xiàn)橢圓的
android:shape=["rectangle" | "oval" | "line" | "ring"]
 shape的形狀,默認為矩形,可以設(shè)置為矩形(rectangle)、橢圓形(oval)、線性形狀(line)、環(huán)形(ring)
然后再放入一個item,這個item是一個左右上下都等長的橢圓
ok,這樣一個等邊的橢圓就做好了

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

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
 <item> 
  <shape android:shape="oval"> 
   <solid android:color="@color/white" /> 
  </shape> 
 </item> 
 <item 
  android:bottom="6dp" 
  android:left="6dp" 
  android:right="6dp" 
  android:top="6dp"> 
  <shape android:shape="oval"> 
   <solid android:color="@color/blue" /> 
  </shape> 
 </item> 
 <item> 
  <shape android:shape="oval"> 
   <stroke 
    android:width="1dp" 
    android:color="@color/blue" 
    android:dashWidth="0dp" /> 
  </shape> 
 </item> 
</layer-list> 

這是一個界面:activity_take_photo.xml
界面的很簡單,這里只是提供參考學(xué)習(xí)的,解釋代碼:
SurfaceView是用來拍照用的,注意這個類只要和視頻或者拍照的都需要用到,不過項目里一般都是自己寫的。
這些代碼只是參考互相學(xué)習(xí),功能的話,自己還在做,所以先提供這些學(xué)習(xí)的...,希望可以幫助學(xué)習(xí)的人,然后自己寫博客的目的也是對自己學(xué)習(xí)的技術(shù)進行收錄和共享,只是本著互相學(xué)習(xí)的目的。

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
 android:layout_width="match_parent" 
 android:layout_height="match_parent" 
 android:background="#ffffff"> 
 
 <!-- 顯示預(yù)覽圖形 --> 
 
 <SurfaceView 
  android:id="@+id/surfaceView" 
  android:layout_width="match_parent" 
  android:layout_height="match_parent" /> 
 
 <RelativeLayout 
  android:id="@+id/buttonLayout" 
  android:layout_width="match_parent" 
  android:layout_height="match_parent" 
  android:background="@drawable/pic"> 
 
  <RelativeLayout 
   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"> 
 
 
   <Button 
    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" /> 
 
   <ImageView 
    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="@drawable/camera_library" /> 
 
   <ImageView 
    android:id="@+id/title_btn_black" 
    android:layout_width="40dp" 
    android:layout_height="40dp" 
    android:layout_alignParentRight="true" 
    android:layout_centerVertical="true" 
    android:layout_marginRight="20dp" 
    android:padding="5dp" 
    android:src="@drawable/camera_back" /> 
  </RelativeLayout> 
 
 
  <LinearLayout 
   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"></LinearLayout> 
 
  <!-- 自定義的標題欄--> 
  <RelativeLayout 
   android:id="@+id/camera_top" 
   android:layout_width="fill_parent" 
   android:layout_height="40dp" 
   android:layout_alignParentTop="true" 
   android:background="@color/black"> 
 
   <ImageView 
    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="@drawable/back" /> 
 
   <ImageView 
    android:id="@+id/btn_change" 
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent" 
    android:layout_alignParentRight="true" 
    android:layout_centerVertical="true" 
    android:paddingBottom="10dp" 
    android:paddingRight="10dp" 
    android:paddingTop="10dp" 
    android:src="@drawable/camera_flip" /> 
 
  </RelativeLayout> 
 
  <!-- 自定義的CameraGrid--> 
  <org.personality.camera.ui.view.CameraGrid 
   android:id="@+id/masking" 
   android:layout_width="match_parent" 
   android:layout_height="match_parent" 
   android:layout_above="@id/photo_area" 
   android:layout_alignParentTop="true" /> 
 
  <View 
   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" /> 
 </RelativeLayout> 
 
</FrameLayout>

 提供自定義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(); 
 } 
 
 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; 
 } 
} 

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 詳解Android(共享元素)轉(zhuǎn)場動畫開發(fā)實踐

    詳解Android(共享元素)轉(zhuǎn)場動畫開發(fā)實踐

    本篇文章主要介紹了詳解Android(共享元素)轉(zhuǎn)場動畫開發(fā)實踐,具有一定的參考價值,感興趣的小伙伴們可以參考一下。
    2017-08-08
  • Android開發(fā)Intent跳轉(zhuǎn)傳遞list集合實現(xiàn)示例

    Android開發(fā)Intent跳轉(zhuǎn)傳遞list集合實現(xiàn)示例

    這篇文章主要為大家介紹了Android開發(fā)Intent跳轉(zhuǎn)傳遞list集合實現(xiàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-07-07
  • Android WebP 圖片壓縮與傳輸

    Android WebP 圖片壓縮與傳輸

    本文主要講解Android WebP 圖片壓縮與傳輸,這里對WebP圖片格式以及如何實現(xiàn)壓縮和傳輸,做了詳細講解,有需要的小伙伴可以參考下
    2016-08-08
  • 簡單實現(xiàn)Android驗證碼

    簡單實現(xiàn)Android驗證碼

    在登錄或者注冊的時候要求輸入驗證碼,這篇文章主要為大家詳細介紹了如何簡單實現(xiàn)Android驗證碼的相關(guān)資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-12-12
  • Android編程設(shè)計模式之模板方法模式詳解

    Android編程設(shè)計模式之模板方法模式詳解

    這篇文章主要介紹了Android編程設(shè)計模式之模板方法模式,結(jié)合實例形式詳細分析了Android模板方法模式的概念、功能、使用場景、用法及相關(guān)操作注意事項,需要的朋友可以參考下
    2017-12-12
  • Android 日常開發(fā)總結(jié)的60條技術(shù)經(jīng)驗

    Android 日常開發(fā)總結(jié)的60條技術(shù)經(jīng)驗

    這篇文章主要介紹了Android日常開發(fā)總結(jié)的技術(shù)經(jīng)驗60條,需要的朋友可以參考下
    2016-03-03
  • Flutter最小刷新范圍探索ValueListenableBuilder使用詳解

    Flutter最小刷新范圍探索ValueListenableBuilder使用詳解

    這篇文章主要為大家介紹了Flutter最小刷新范圍探索ValueListenableBuilder使用詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-12-12
  • Android  Spinner列表選擇框的應(yīng)用

    Android Spinner列表選擇框的應(yīng)用

    這篇文章主要介紹了Android Spinner列表選擇框的應(yīng)用的相關(guān)資料,這里對spinner的屬性和常用事件和數(shù)據(jù)綁定都做了介紹,需要朋友可以參考下
    2017-07-07
  • android實現(xiàn)快遞跟蹤進度條

    android實現(xiàn)快遞跟蹤進度條

    這篇文章主要為大家詳細介紹了android實現(xiàn)快遞跟蹤進度條,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-05-05
  • Android Studio 3.0 Gradle 配置變更

    Android Studio 3.0 Gradle 配置變更

    這篇文章主要介紹了Android Studio 3.0 Gradle 配置變更的相關(guān)知識,即多渠道打包變更和更改打包命名及路徑的代碼,感興趣的朋友跟隨腳本之家小編一起看看吧
    2018-03-03

最新評論

丹阳市| 茂名市| 恩平市| 永靖县| 衡东县| 临夏市| 嘉祥县| 南安市| 巴林左旗| 浮梁县| 上犹县| 石林| 兴文县| 米林县| 西宁市| 娄底市| 通榆县| 台中市| 新龙县| 太谷县| 丽水市| 宝兴县| 郴州市| 威远县| 织金县| 同仁县| 保靖县| 杭锦后旗| 鞍山市| 镇坪县| 康平县| 静宁县| 会东县| 陵水| 台东县| 平江县| 承德县| 和政县| 泽库县| 清徐县| 沙田区|