我们先实现拍照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>

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" style="width:236px; height:411px">

这是一个界面: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"> <!-- 显示预览图形 --> <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;
}
}

Android实现一个自己定义相机的界面的更多相关文章

  1. Android调用系统相机、自己定义相机、处理大图片

    Android调用系统相机和自己定义相机实例 本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,而且因为涉及到要把拍到的照片显示出来,该样例也会涉及到Android载入大图片时候的处 ...

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

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

  3. android开发——自己定义相机(Camera)开发总结

    近期这段时间我一直在开发自己定义相机.谷歌了些网上的demo.发现有非常多各种各样的问题.终于还是从API的camera类開始学习,进行改进. 以下对之前的实现进行一些总结. 官方camera API ...

  4. 【Android】自己定义相机的实现(支持连续拍照、前后摄像头切换、连续对焦)

    ~转载请注明http://blog.csdn.net/u013015161/article/details/46921257 介绍 这几天.写了一个自己定义照相机的demo.支持连续拍照和摄像头切换. ...

  5. Android Camera API/Camera2 API 相机预览及滤镜、贴纸等处理

    Android Lollipop 添加了Camera2 API,并将原来的Camera API标记为废弃了.相对原来的Camera API来说.Camera2是又一次定义的相机 API,也重构了相机 ...

  6. Android图形显示系统——上层显示1:界面绘制大纲

    Android显示之应用界面绘制 越到上层,跟业务关联越直接.代码就越繁杂.Android上层显示的代码正是如此.此外,java语言本身繁复的特点(比C语言多了满屏的try-catch,比C++少了析 ...

  7. Android 用 camera2 API 自定义相机

    前言 笔者因为项目需要自定义相机,所以了解了一下 Android 关于 camera 这块的 API.Android SDK 21(LOLLIPOP) 开始已经弃用了之前的 Camera 类,提供了 ...

  8. Android中View自己定义XML属性具体解释以及R.attr与R.styleable的差别

    为View加入自己定义XML属性 Android中的各种Widget都提供了非常多XML属性,我们能够利用这些XML属性在layout文件里为Widget的属性赋值. 例如以下所看到的: <Te ...

  9. Android应用之——自己定义控件ToggleButton

    我们经常会看到非常多优秀的app上面都有一些非常美丽的控件,用户体验非常好.比方togglebutton就是一个非常好的样例,IOS系统以下那个精致的togglebutton现在在android以下也 ...

随机推荐

  1. java死锁问题

    一.先从定义上了解一下死锁 二.从代码角度上去解释一下死锁问题 三.上述程序就是出现了死锁,我们来查看一下 1.命令如下   cmd>>jps(查看到了死锁线程所在的类,前面是PID) 2 ...

  2. Java 8 和 Java 9部分区别

    Java 8 和 Java 9中 concurrent 包有了一些改变, 本文对这些改变做了汇总.Java 8 中 Concurrent package的改变java.util.concurrent中 ...

  3. webpack常见问题

    概念问题一:什么是webpack和grunt和gulp有什么不同 答案:Webpack是一个模块打包器,他可以递归的打包项目中的所有模块,最终生成几个打包后的文件.他和其他的工具最大的不同在于他支持c ...

  4. Vue2.0 —生命周期和钩子函数

    vue生命周期简介 咱们从上图可以很明显的看出现在vue2.0都包括了哪些生命周期的函数了. 生命周期探究 对于执行顺序和什么时候执行,看上面两个图基本有个了解了.下面我们将结合代码去看看钩子函数的执 ...

  5. BZOJ 1058: [ZJOI2007]报表统计 multiset + 卡常

    Code: #include<bits/stdc++.h> #define maxn 600000 #define inf 1000000000 using namespace std; ...

  6. java代码完全手写模仿qq登录界面

    这是我模仿QQ2015版界面,实现的基本功能有登陆验证,重置等,当然直接复制代码运行是不一样的,还要注意自己插入自己的图片. 结果截图如下所示: import java.awt.BorderLayou ...

  7. JavaScript day1(注释)

    JavaScript中的注释方式有两种: 单行注释,使用 //. // This is an in-line comment. 多行注释,以/*开始,用*/来结束. /* This is a mult ...

  8. C++ Primer(第4版)-学习笔记-第3部分:类和数据抽象

    第12章 类       每个类可以没有成员,也可以定义多个成员,成员可以是数据.函数或类型别名. 成员函数必须在类内部声明,可以在类内部定义,也可以在类外部定义.如果在类内部定义,就默认是内联函数. ...

  9. java中通用权限管理设计(转)

    原文地址:http://www.cnblogs.com/a7345678/archive/2008/09/25/1298838.html 转自博客园暗夜精灵-鬼才阁 实现业务系统中的用户权限管理 B/ ...

  10. 团队一致性的PHP开发环境之Vagrant

    Vagrant 简介 Vagrant是一个基于Ruby的工具,用于创建和部署虚拟化开发环境. 它的主要意义是让所有开发人员都使用和线上服务器一样的环境,本质上和你新建一个虚拟机 安装 # https: ...