Android Custom Camera Interface implementation code _android

Source: Internet
Author: User
Tags xmlns

We first realize the circular effect of the photo button ha, Android development, of course, you can find art designers to design pictures, and then directly brought in, but we can write their own code to achieve this effect ha, the most commonly used is the layout-list to achieve the superposition of pictures, we this layout named BTN _take_photo.xml, this is a custom drawable file, so according to the spec, we're going to put it in the Drawable folder.

Note:The drawable folder is typically a custom drawable file that can be viewed as a background style for your own writing, and so on.

Explanation Code:

Layer-list inside put 3 item, first realizes a white background ellipse, the attribute android:shape= "Oval" is realizes the ellipse
android:shape=["Rectangle" | "Oval" | "Line" | "Ring"]
Shape shapes, default to rectangles, can be set to rectangular (rectangle), elliptic (oval), linear shape (line), annular (ring)
And then put an item, this item is an ellipse with an equal length of up and down
OK, so an equilateral oval is done.

And then put it again into a blue background oval

<?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> 

This is an interface: Activity_take_photo.xml
Interface is very simple, here is just a reference to learn, explain the code:
Surfaceview is used for photography, note that this class as long as the video or the camera need to use, But the project is usually written by himself.
The 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 learning people, and then write their own blog is also the purpose of their own learning technology to collect and share, but the purpose of learning from each other.

<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 A Ndroid: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_pa Rent "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" Andro id:background= "@color/white" android:gravity= "center_vertical" android:padding= "2DP" > <button A Ndroid: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 Andr Oid:id= "@+id/iv_album" android:layout_width= "40DP" android:layout_height= "40DP" Android:layout_alignparentl 
    Eft= "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:layo Ut_width= "40DP" android:layout_height= "40DP" android:layout_alignparentright= "true" Android:layout_centerve Rtical= "true" android:layout_marginright= "20DP" android:padding= "5DP" android:src= "@drawable/camera_back"/ > </RelativeLayout> <linearlayout android:id= "@+id/photo_area" android:layout_width= "Fill_pa Rent "android:layout_height=" wrap_content "android:layout_above=" @id/panel_take_photo "Android:layout_centerve Rtical= "true" Android:background= "@color/white" android:orientation= "Horizontal" ></LinearLayout> <!--custom title bar--> &L T 
   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_alignPar" Entleft= "true" android:paddingbottom= "10DP" android:paddingleft= "10DP" android:paddingtop= "10DP" Andro id:src= "@drawable/back"/> <imageview android:id= "@+id/btn_change" android:layout_width= T "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> <!--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_inde X "android:layout_width=" 40DP "android:layout_height=" 40DP "android:layout_above=" @id/photo_area "Android: background= "@drawable/cam_focus" android:visibility= "invisible"/> </RelativeLayout> </framelayout&gt ;

Provide custom Cameragrid classes:

/** 
 * Custom View 
 * Camera well Word line */ 
 public 
class Cameragrid extends View { 
 
 private int topbannerwidth = 0; 
 Private Paint Mpaint; 
 
 Public Cameragrid {This 
  (context,null); 
 } 
 
 Public Cameragrid (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; 
 } 

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.