Android自定義相機(jī)界面的實(shí)現(xiàn)代碼
我們先實(shí)現(xiàn)拍照按鈕的圓形效果哈,Android開發(fā)中,當(dāng)然可以找美工人員設(shè)計(jì)圖片,然后直接拿進(jìn)來,不過我們可以自己寫代碼實(shí)現(xiàn)這個(gè)效果哈,最常用的的是用layout-list實(shí)現(xiàn)圖片的疊加,我們這個(gè)layout命名為btn_take_photo.xml,這是一個(gè)自定義的drawable文件,所以按照規(guī)范,我們要將它放在drawable文件夾里。
注意:drawable文件夾一般是來放自定義的drawable文件的,可以將它看成自己寫的背景樣式等等哦
解釋代碼:
layer-list里面放3個(gè)item,先實(shí)現(xiàn)一個(gè)白色背景的橢圓,屬性android:shape="oval"是實(shí)現(xiàn)橢圓的
android:shape=["rectangle" | "oval" | "line" | "ring"]
shape的形狀,默認(rèn)為矩形,可以設(shè)置為矩形(rectangle)、橢圓形(oval)、線性形狀(line)、環(huán)形(ring)
然后再放入一個(gè)item,這個(gè)item是一個(gè)左右上下都等長的橢圓
ok,這樣一個(gè)等邊的橢圓就做好了
接著再次放入一個(gè)一個(gè)藍(lán)色背景的橢圓
<?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> 
這是一個(gè)界面:activity_take_photo.xml
界面的很簡單,這里只是提供參考學(xué)習(xí)的,解釋代碼:
SurfaceView是用來拍照用的,注意這個(gè)類只要和視頻或者拍照的都需要用到,不過項(xiàng)目里一般都是自己寫的。
這些代碼只是參考互相學(xué)習(xí),功能的話,自己還在做,所以先提供這些學(xué)習(xí)的...,希望可以幫助學(xué)習(xí)的人,然后自己寫博客的目的也是對(duì)自己學(xué)習(xí)的技術(shù)進(jìn)行收錄和共享,只是本著互相學(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>
<!-- 自定義的標(biāo)題欄-->
<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
* 照相機(jī)井字線
*
*/
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)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android自定義相機(jī)聚焦和顯示框
- Android自定義相機(jī)Camera實(shí)現(xiàn)手動(dòng)對(duì)焦的方法示例
- android 7自定義相機(jī)預(yù)覽及拍照功能
- Android開源庫自定義相機(jī)模塊
- Android 自定義相機(jī)及分析源碼
- Android 用 camera2 API 自定義相機(jī)
- Android中關(guān)于自定義相機(jī)預(yù)覽界面拉伸問題
- Android自定義相機(jī)實(shí)現(xiàn)定時(shí)拍照功能
- Android自定義相機(jī)實(shí)現(xiàn)自動(dòng)對(duì)焦和手動(dòng)對(duì)焦
- Android自定義相機(jī)、預(yù)覽區(qū)域裁剪
相關(guān)文章
詳解Android(共享元素)轉(zhuǎn)場動(dòng)畫開發(fā)實(shí)踐
本篇文章主要介紹了詳解Android(共享元素)轉(zhuǎn)場動(dòng)畫開發(fā)實(shí)踐,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。2017-08-08
Android開發(fā)Intent跳轉(zhuǎn)傳遞list集合實(shí)現(xiàn)示例
這篇文章主要為大家介紹了Android開發(fā)Intent跳轉(zhuǎn)傳遞list集合實(shí)現(xiàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-07-07
簡單實(shí)現(xiàn)Android驗(yàn)證碼
在登錄或者注冊的時(shí)候要求輸入驗(yàn)證碼,這篇文章主要為大家詳細(xì)介紹了如何簡單實(shí)現(xiàn)Android驗(yàn)證碼的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-12-12
Android編程設(shè)計(jì)模式之模板方法模式詳解
這篇文章主要介紹了Android編程設(shè)計(jì)模式之模板方法模式,結(jié)合實(shí)例形式詳細(xì)分析了Android模板方法模式的概念、功能、使用場景、用法及相關(guān)操作注意事項(xiàng),需要的朋友可以參考下2017-12-12
Android 日常開發(fā)總結(jié)的60條技術(shù)經(jīng)驗(yàn)
這篇文章主要介紹了Android日常開發(fā)總結(jié)的技術(shù)經(jīng)驗(yàn)60條,需要的朋友可以參考下2016-03-03
Flutter最小刷新范圍探索ValueListenableBuilder使用詳解
這篇文章主要為大家介紹了Flutter最小刷新范圍探索ValueListenableBuilder使用詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-12-12
android實(shí)現(xiàn)快遞跟蹤進(jìn)度條
這篇文章主要為大家詳細(xì)介紹了android實(shí)現(xiàn)快遞跟蹤進(jìn)度條,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-05-05
Android Studio 3.0 Gradle 配置變更
這篇文章主要介紹了Android Studio 3.0 Gradle 配置變更的相關(guān)知識(shí),即多渠道打包變更和更改打包命名及路徑的代碼,感興趣的朋友跟隨腳本之家小編一起看看吧2018-03-03

