Android Studio初认识——调用相机

//////////////////////2015/08/28///////////////

/////////////////////by XBW ///////////////////

///////////////////环境 Android Studio///

初学习Android Studio确实不知道从哪下手,网络视频课也没找到,索性弄了一下调用系统摄像机吧;看一下效果吧

这是了解之后自己认为编辑时需要用到的几个xml文件,AndroidMainfest.xml自己理解的是一些配置信息,因为自己把调用摄像机的权限写在这个文件中了,看一下代码;

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myapplication" >

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
                //<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
                <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
                <uses-permission android:name="android.permission.CAMERA" />
                <uses-permission android:name="android.permission.RECORD_AUDIO" />
                <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
            </intent-filter>
        </activity>
    </application>

</manifest>

MainActivity.xml经过实践证明应该是主程序的,我把那个我的相机按钮的时间写在其中还有那个退出的菜单,

package com.example.myapplication;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.provider.MediaStore;
public class MainActivity extends ActionBarActivity {
    private Button button;
    private ImageView view;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        button = (Button) findViewById(R.id.button1);
                view= (ImageView)findViewById(R.id.imageView1);
        button.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                startActivityForResult(intent, 1);
            }
                });

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            finish();
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

activity_main.xml自认为是设计界面的,而且我还发现后来的代码的图片会把之前的代码的图片覆盖掉,应该也是层级显示吧

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
    <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"/>
            //android:src="@drawable/ic_launcher" />

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/pic"
        android:layout_alignParentTop="true"
        android:layout_alignParentBottom="true" />
    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="我的相机"
        android:background="@drawable/pic2"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true" />
    <TextView android:text="@string/hello_world" android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</RelativeLayout>

好吧,这根本就不是分享,我只是记个笔记而已,不要想多了,初学者………………

至于那两张图片怎么添加进去的,我说了不要骂我,我是点的show in explorer,然后把图片复制进去了,嘿嘿,英语差没办法;

还了解到一个实用的地方,也就是MFC的ID吧估计

这样呢,只要我们在用到的时候只需要@string/hello world或者其他就好了,还不错;

选择真机进行测试就好了,

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-08-03 17:11:45

Android Studio初认识——调用相机的相关文章

Android Studio初体验之启动AVD模拟器异常:cannot set up guest memory &#39;pc.ram&#39;

启动AVD模拟器异常:Cannot set up guest memory 'pc.ram' 错误信息: HAX is working and emulator runs in fast virt mode Cannot set up guest memory 'pc.ram': Invalid argument Error accepting connect 分析 各种查资料,没有发现网上有同样问题的,在一篇相关文章中找到类似的解决方法. 从语意看,应该是hax安装后没有启动.(不懂hax是什

Android Studio 初体验

Google在I/O2013大会上公布了Android新的开发工具Android Studio,趁周末时间做了一下尝试.有须要的能够 在http://developer.android.com/sdk/installing/studio.html下载,当前版本号是V0.1.官方解释:Android Studio is a new Android development environment based on IntelliJ IDEA. Similar to Eclipse with the

【走过巨坑】android studio对于jni调用及运行闪退无法加载库的问题解决方案

相信很多小伙伴都在android开发中遇到调用jni的各种巨坑,因为我们不得不在很多地方用到第三方库so文件,然而第三方官方通常都只会给出ADT环境下的集成方式,而谷歌亲儿子android studio默认采用的却是gradle方式,与ADT编辑的方式大不相同,那再andorid studio中如何导入so文件呢? 在android studio 中我们可能会用到jar包和so文件的方式,对于jar包可能接触更多,只需要我们把工程转换为project显示方式,打开app下的libs文件夹,导入即

Android Studio 初体验,从Eclipse到AS

这些天一直在忙着面试方面的准备以及不断更新完善我的Memory软件,不知不觉过去了好久. 由于我想对软件加入一些material design的新元素,因此去网上找对应的示例源码,突然发现除了各种教程上还在使用eclipse,这个世界几乎所有新的东东都被AndroidStudio包揽了,瞬间感觉不学AS简直就是不可逾越的交流鸿沟.因此网上买了个VPN翻墙,用了几天时间,终于搞明白了AS的基本用法.在此分享一下自己的学习心得. 自己是从Eclipse转到AS上的,所以在学习AS当中, 必然下意识的

Android studio初认识及环境搭建

////////////2015/08/26////////////// ////////////by XBW/////////////////// ///////////环境 android studio// 今天有幸了解到android studio这个apk的开发平台,通过几张界面的图片就深深的感觉到比eclipse强的不是一点半点,仅仅界面就吸引了我,为什么没再继续QT呢,毕竟安卓的亲爷爷还是JAVA,用C++鼓捣安卓还有点不妥,不是长久之计,这样呢,我就开始配置环境了. 链接:http

Android Studio初体验之导入eclipse项目

本篇使用到的Android Studio版本为1.0, Eclipse ADT版本22.3.0. 主要介绍两种导入方式: 先用Eclipse导出为Gradle build files,然后直接用Android Studio导入该项目. 用Android Studio 直接导入Eclipse项目. Android Studio默认使用 Gradle 构建项目, Eclipse 默认使用Ant构建项目.建议Android Studio导入项目时,使用 Gradle 构建项目. 导出Eclipse 项

Android Studio 初使用

Android Studio 更改Eclipse快捷键 Android Studio 更改编码 Android Studio 导包

[Android Pro] Android studio jni中调用Log输出调试信息

reference to : http://www.linuxidc.com/Linux/2014-02/96341.htm Android 开发中,java 可以方便的使用调试信息Log.i, Log.d ...,Jni层可否使用呢?答案是肯定的. 1 为方便使用,先进行宏定义: eben_hpc_log.h内容如下: #ifndef _Included_hpc_Log#define _Included_hpc_Log#ifdef __cplusplusextern "C" {#en

Android Studio初体验之揭秘AS的项目的目录结构

(因为是初步,难免有错误出现,如果哪里记录的有问题,欢迎各位指正,共同成长) 我们默认你的AS是已经安装并好的,关于AS的安装,网上一大把,请各位自行寻找资源 下面记录一些配置以及AS的项目的目录结构 配置: 1.config:用户的配置文件,保存用户的个人设置(你所设置的所有的熟悉,注意备份,就不会一次次去设置)   2.restart:不用关心   3.system:运行的生成的缓存环境(会越来越大) ①考虑配置在磁盘空间大的磁盘中 ②可以删除,但是第一次使用的时候会初始化一些数据 项目结构