我们先实现拍照button的圆形效果哈。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,这样一个等边的椭圆就做好了

接着再次放入一个一个蓝色背景的椭圆

<?

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

界面的非常easy,这里仅仅是提供參考学习的。解释代码:

SurfaceView是用来拍照用的。注意这个类仅仅要和视频或者拍照的都须要用到,只是项目里一般都是自己写的

这些代码仅仅是參考互相学习,功能的话,自己还在做。所以先提供这些学习的...,希望能够帮助学习的人,然后自己写博客的目的也是对自己学习的技术进行收录和共享,仅仅是本着互相学习的目的

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:background="#ffffff"><!-- 显示预览图形 --><SurfaceViewandroid:id="@+id/surfaceView"android:layout_width="match_parent"android:layout_height="match_parent" /><RelativeLayoutandroid:id="@+id/buttonLayout"android:layout_width="match_parent"android:layout_height="match_parent"android:background="@drawable/pic"><RelativeLayoutandroid: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"><Buttonandroid: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" /><ImageViewandroid: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" /><ImageViewandroid: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><LinearLayoutandroid: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><!-- 自己定义的标题栏--><RelativeLayoutandroid:id="@+id/camera_top"android:layout_width="fill_parent"android:layout_height="40dp"android:layout_alignParentTop="true"android:background="@color/black"><ImageViewandroid: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" /><ImageViewandroid: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.CameraGridandroid:id="@+id/masking"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_above="@id/photo_area"android:layout_alignParentTop="true" /><Viewandroid: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;}
}

转载于:https://www.cnblogs.com/gavanwanggw/p/7136282.html

Android实现一个自己定义相机的界面相关推荐

  1. Android 手把手带你玩转自己定义相机

    本文已授权微信公众号<鸿洋>原创首发,转载请务必注明出处. 概述 相机差点儿是每一个APP都要用到的功能,万一老板让你定制相机方不方?反正我是有点方. 关于相机的两天奋斗总结免费送给你. ...

  2. Android编写一个登录界面,利用数据库实现记住密码,注册账号,强制下线,以及类似QQ的下拉列表登录功能

    首先呢,看到这么长的标题,是不是感觉这些功能有点难以实现呢,哈哈,其实并没有想象中的那么复杂,下面就跟着笔者来一起学习一下这些功能是怎么实现的吧! 1.建立一个所有活动的父类,继承自Appcompat ...

  3. android界面布局题,【填空题】Android 系统中, 用于定义布局显示在界面上的风格。...

    [填空题]Android 系统中, 用于定义布局显示在界面上的风格. 更多相关问题 [37]A.anotherB.each otherC.the otherD.one another Tabor ma ...

  4. android软件欢迎界面,Android应用中实现一个软件启动的欢迎界面

    在一个Android应用启动时,可以根据需要为其设置一个欢迎界面.欢迎界面将是用户在启动应用 时看到的第一个界面,传达给用户第一感觉. 下面的几个web,各自提供了一种实现方式. 1.不用线程做And ...

  5. 【Android 开发】SufaceView自定义相机拍照

    前段时间写了关于一篇关于调用系统相机的博客,如果需要调用系统相机和截图可以看一看这篇博客:Android学习之调用系统相机拍照.截图并保存最近发现不同手机,调用系统相机效果不太好,,所以学习Andro ...

  6. (转载)Android GradientDrawable(shape标签定义) 静态使用和动态使用(圆角,渐变实现)

    最近被吐槽界面太丑,还是很尴尬的,全公司就一个UI设计师,所以很多事情还是不忍直视,一个同事问我,背景可不可以使用渐变的感觉,然后我就有种突然感觉眼前一亮的感觉.还真的没有做过这方面的东西,单纯使用渐 ...

  7. Android应用开发:数据存储和界面展现-1

    1. 相对布局RelativeLayout 特点:相对布局所有组件可以叠加在一起:各个组件的布局是独立的,互不影响:所有组件的默认位置都是在左上角(顶部.左部对齐) 属性 功能描述 android:l ...

  8. android让一个控件跟上面控件对其,学个明白--Android控件架构

    Android控件架构 1.什么是View? View是Android中所有控件的基类.View是界面层的控件的一种抽象,它代表了一个控件.在Android中每个控件都会在界面中占得一块矩形的区域.在 ...

  9. Android 二维码扫描(仿微信界面),根据Google zxing

    Android 二维码扫描(仿微信界面),根据Google zxing Android项目开发中经常会用到二维码扫描,例如登陆.支付等谷歌方面已经有了一个开源库(地址: https://github. ...

最新文章

  1. mysqladmin flush-hosts 解决方法
  2. 通过jquery-ui中的sortable来实现拖拽排序
  3. ruby 爬虫爬取拉钩网职位信息,产生词云报告
  4. vuejs中 vmode_在VueJS中发现封闭的力量
  5. MySQL表连接(join)
  6. Android如何获取Wifi名称即SSID
  7. underscore源码经典--收藏
  8. 至 上海神力科技有限公司 的留言 http://www.sl-power.com/
  9. 2-36进制,可以任意进制互转的类
  10. CSS样式的简单使用
  11. 计算机专业英语词汇1695词(35天记忆)
  12. 消息摘要(Message Digest)及其算法
  13. 京东官网首页js+css+html基础
  14. 【整理向】老板让我用SPSS做A/Btest,我偏要用python
  15. python 算24 代码
  16. 缓慢画点功能实现的两个方法
  17. codeforces1438C Engineer Artem (#682 Div2)
  18. Linux 网桥配置br-lan、eth0、eth1、ra0、rai0
  19. 深度强化学习(DRL)简介与常见算法(DQN,DDPG,PPO,TRPO,SAC)分类
  20. android 仿微信语音聊天

热门文章

  1. vue 加载页面时触发时间_解析Vue项目的四个方面优化
  2. springboot项目层次结构_Spring Boot 默认的指标数据从哪来的?
  3. missing 1 required positional argument: 'on_delete'报错解决方案
  4. Spring boot 整合 Mybatis 实现增删改查(MyEclipse版)
  5. [剑指offer] 跳台阶
  6. 关闭ES动态创建type
  7. ::selection 制作空心字
  8. MFC 关于new出一个新对话框时,退出对话框内存泄漏的问题解决
  9. 解决:org.xml.sax.SAXParseException: 元素类型 “head“ 必须由匹配的结束标记 “</head>问题
  10. 由于SSH配置文件的不匹配,导致的Permission denied (publickey)及其解决方法