//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或者其他就好了,还不错;
选择真机进行测试就好了,