Android自定義相機(jī)界面的實(shí)現(xiàn)代碼
我們先實(shí)現(xiàn)拍照按鈕的圓形效果哈,Android開發(fā)中,當(dāng)然可以找美工人員設(shè)計(jì)圖片,然后直接拿進(jìn)來(lái),不過(guò)我們可以自己寫代碼實(shí)現(xiàn)這個(gè)效果哈,最常用的的是用layout-list實(shí)現(xiàn)圖片的疊加,我們這個(gè)layout命名為btn_take_photo.xml,這是一個(gè)自定義的drawable文件,所以按照規(guī)范,我們要將它放在drawable文件夾里。
注意:drawable文件夾一般是來(lái)放自定義的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è)左右上下都等長(zhǎng)的橢圓
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
界面的很簡(jiǎn)單,這里只是提供參考學(xué)習(xí)的,解釋代碼:
SurfaceView是用來(lái)拍照用的,注意這個(gè)類只要和視頻或者拍照的都需要用到,不過(guò)項(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; } }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android自定義相機(jī)聚焦和顯示框
- Android自定義相機(jī)Camera實(shí)現(xiàn)手動(dòng)對(duì)焦的方法示例
- android 7自定義相機(jī)預(yù)覽及拍照功能
- Android開源庫(kù)自定義相機(jī)模塊
- Android 自定義相機(jī)及分析源碼
- Android 用 camera2 API 自定義相機(jī)
- Android中關(guān)于自定義相機(jī)預(yù)覽界面拉伸問(wèn)題
- Android自定義相機(jī)實(shí)現(xiàn)定時(shí)拍照功能
- Android自定義相機(jī)實(shí)現(xiàn)自動(dòng)對(duì)焦和手動(dòng)對(duì)焦
- Android自定義相機(jī)、預(yù)覽區(qū)域裁剪
相關(guān)文章
Android開發(fā)筆記之:Handler Runnable與Thread的區(qū)別詳解
本篇文章是對(duì)在Android中Handler Runnable與Thread的區(qū)別進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-05-05Android自定義View實(shí)現(xiàn)隨手勢(shì)滑動(dòng)控件
這篇文章主要為大家詳細(xì)介紹了Android自定義View實(shí)現(xiàn)隨手勢(shì)滑動(dòng)的控件,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-02-02利用adt-bundle輕松搭建Android開發(fā)環(huán)境與Hello world(Windows)
這篇文章主要介紹了利用adt-bundle在Windows下輕松搭建Android開發(fā)環(huán)境與Hello world,感興趣的小伙伴們可以參考一下2016-07-07android仿華為手機(jī)懸浮窗設(shè)計(jì)
這篇文章主要為大家詳細(xì)介紹了android仿華為手機(jī)懸浮窗設(shè)計(jì),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-08-08Flutter?Widget之NavigationBar使用詳解
這篇文章主要為大家介紹了Flutter?Widget之NavigationBar使用詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-12-12Android進(jìn)程間使用Intent進(jìn)行通信
Android進(jìn)程間通信(IPC,Inter-Process Communication)底層采用的是 Binder 機(jī)制,具體到應(yīng)用層有網(wǎng)友根據(jù)安卓四大組件將進(jìn)程間通信方式分為對(duì)應(yīng)的四種方式 Activity, Broadcast, ContentProvider, Service2023-02-02OnSharedPreferenceChangeListener詳解及出現(xiàn)不觸發(fā)解決辦法
本文主要介紹 Android OnSharedPreferenceChangeListener的知識(shí),在Android應(yīng)用開發(fā)過(guò)程中會(huì)遇到監(jiān)聽器不觸發(fā)事件問(wèn)題,這里介紹了相應(yīng)的解決辦法2016-08-08Android 網(wǎng)絡(luò)請(qǐng)求框架解析之okhttp與okio
HTTP是現(xiàn)代應(yīng)用常用的一種交換數(shù)據(jù)和媒體的網(wǎng)絡(luò)方式,高效地使用HTTP能讓資源加載更快,節(jié)省帶寬,OkHttp是一個(gè)高效的HTTP客戶端,下面這篇文章主要給大家介紹了關(guān)于OkHttp如何用于安卓網(wǎng)絡(luò)請(qǐng)求,需要的朋友可以參考下2021-10-10Android進(jìn)階Hook攔截系統(tǒng)實(shí)例化View過(guò)程實(shí)現(xiàn)App換膚功能
這篇文章主要為大家介紹了Android進(jìn)階Hook攔截系統(tǒng)實(shí)例化View過(guò)程實(shí)現(xiàn)App換膚功能詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-01-01詳解Android通過(guò)修改配置文件設(shè)置wifi密碼
這篇文章主要介紹了詳解Android通過(guò)修改配置文件設(shè)置wifi密碼的相關(guān)資料,需要的朋友可以參考下2017-07-07