Android implements a self-defined camera interface

Source: Internet
Author: User

Let's start with the round effect of the snap button. Android development, of course, can find artists to design pictures, and then directly brought in. It's just that we can write our own code to achieve this effect. The most commonly used is to use the layout-list implementation of the image overlay, our layout named Btn_take_photo.xml, which is a self-defined drawable file, so according to the specification, we want to put it in the drawable directory

Note: The drawable directory is usually used to put your own definition of the drawable file, to be able to regard it as a background style of writing and so on OH

Explanation Code:

Layer-list put 3 Item, first implement a white background ellipse, the attribute android:shape= "Oval" is the implementation of the ellipse

android:shape=["Rectangle" | "Oval" | "Line" | "Ring"]

Shape, default feel rectangle, can be set to rectangle (rectangle), oval (oval), linear shape (line), annular (ring)

And then put in an item. This item is an oval that is equal to the left and right.

OK, so an equilateral ellipse is ready.

Then put the ellipse in a blue background again

<?

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 "style=" WIDTH:236PX; height:411px ">


This is an interface: Activity_take_photo.xml

The interface is very easy, here is only to provide reference study. Explanation Code:

Surfaceview is used for photographic purposes. Note that this class only needs to be used with video or photography, but it is usually written in the project itself.

The code is only a reference to learn from each other, the function of the words, they are still doing. So the first to provide these learning ..., hope to help the study of the people, and then write their own blog is the purpose of their own learning technology to be included and shared, only in the spirit of mutual learning purposes

<framelayout xmlns:android= "http://schemas.android.com/apk/res/android" android:layout_width= "Match_parent"        android:layout_height= "Match_parent" android:background= "#ffffff" > <!--Show preview Graphics--<surfaceview Android:id= "@+id/surfaceview" android:layout_width= "match_parent" android:layout_height= "Match_parent"/&G    T <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_v                Ertical "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= "t Rue "android:layout_marginleft=" 20DP "android:padding=" 5DP "android:src=" @dra Wable/camera_library "/> <imageview android:id=" @+id/title_btn_black "Andro                Id:layout_width= "40DP" android:layout_height= "40DP" android:layout_alignparentright= "true" Android:layout_centervertical= "true" android:layout_marginright= "20DP" Android          :p adding= "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:backgro        und= "@color/white" android:orientation= "Horizontal" ></LinearLayout> <!--own defined title bar-- <relativelayout android:id= "@+id/camera_top" android:layout_width= "Fill_parent" and             roid: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" Andro Id:paddingbottom= "10DP"               android:paddingleft= "10DP" android:paddingtop= "10DP" android:src= "@drawable/b Ack "/> <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:paddingrigh t= "10DP" android:paddingtop= "10DP" android:src= "@drawable/camera_flip"/> </rel ativelayout> <!--own definition of cameragrid--> <org.personality.camera.ui.view.cameragrid Andro            Id: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=" @i D/photo_area "android:background=" @drawable/cam_focus "android:visibility=" invisible "/> </ Relativelayout></framelayout>


Provide your own definition of the Cameragrid class:

/** * self-defined view * Camera well Word line * */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 (+);        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 implements a self-defined camera interface

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.