Android implements a custom camera interface

Source: Internet
Author: User

We first achieve the round effect of the camera button Ah, Android development, of course, you can find the artist design pictures, and then directly brought in, but we can write their own code to achieve this effect ha, the most commonly used is to use layout-list to achieve the image overlay, our layout named btn _take_photo.xml, this is a custom drawable file, so by the spec, we're going to put it in the Drawable folder.

Note: The Drawable folder is generally used to put the custom drawable file, you can see it as your own writing background style 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, which is the default rectangle, can be set to rectangle (rectangle), oval (oval), linear shape (line), Loop (ring)

Then put in an item, this item is an ellipse 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>



This is an interface: Activity_take_photo.xml

The interface is very simple, here is just to provide reference to learn, explain the code:

Surfaceview is used for photo-taking, note that this class as long as the video or photography needs to be used, but the project is usually written on their own

These code is only reference to learn from each other, the function of the words, they are still doing, so the first to provide these learning ..., hope can help the study of the people, and then write their own blog is the purpose of their own learning technology to collect and share, but 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> <!--custom title bar-- <relativelayout android:id= "@+id/camera_top" android:layout_width= "Fill_parent" Android            oid: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" Androi  D:paddingbottom= "10DP"              android:paddingleft= "10DP" android:paddingtop= "10DP" android:src= "@drawable/ba ck "/> <imageview android:id=" @+id/btn_change "android:layout_width=" Wrap_c                Ontent "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"/> </rela tivelayout> <!--custom 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 "/> </re Lativelayout></framelayout>


Provides a custom Cameragrid class:

/** * Custom 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 custom camera interface

Related Article

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.