当前位置: 编程技术>移动开发
本页文章导读:
▪透过编码方式实现软件的布局 通过编码方式实现软件的布局程序运行结果图示:
需要注意的是:
1)一个控件只能有一个父元素,如果多次添加
09-02 11:01:34.785: E/AndroidRuntime(23954):
java.lang.RuntimeException: Unable to start activit.........
▪ 视频刻录的简略实现 视频刻录的简单实现本代码可能在不用的平台上会存在一些问题。。
但是主要方法还是一样的
1、main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/.........
▪ makefile编纂差异 makefile编写差异由于zlib动态库在linux下引用的问题引出了对于简练的makefile的学习。之前通过看网络上的一些文章自己也算简单了解如何编写一个makefile,可总是不那么美观,今天经过辉哥的.........
[1]透过编码方式实现软件的布局
来源: 互联网 发布时间: 2014-02-18
通过编码方式实现软件的布局
程序运行结果图示:
需要注意的是:
1)一个控件只能有一个父元素,如果多次添加
09-02 11:01:34.785: E/AndroidRuntime(23954):
java.lang.RuntimeException: Unable to start activity ComponentInfo{cn.itcast.codeui/cn.itcast.codeui.MainActivity}: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
1、把新建项目时的main.xml文件删除
2、MainActivity
package com.njupt.codeui; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view.ViewGroup.LayoutParams; import android.widget.Button; import android.widget.EditText; import android.widget.LinearLayout; import android.widget.TextView; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT); LayoutParams params1 = new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT); LayoutParams params2 = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT); LinearLayout linearLayout = new LinearLayout(this); linearLayout.setOrientation(LinearLayout.VERTICAL); TextView tv = new TextView(this); tv.setText("请输入你的老婆的姓名"); linearLayout.addView(tv,params1); EditText et = new EditText(this); et.setText("章泽天"); linearLayout.addView(et,params1); Button bt = new Button(this); bt.setText("确定"); linearLayout.addView(bt,params2); setContentView(linearLayout,params); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }
[2] 视频刻录的简略实现
来源: 互联网 发布时间: 2014-02-18
视频刻录的简单实现
本代码可能在不用的平台上会存在一些问题。。
但是主要方法还是一样的
1、main.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <SurfaceView android:id="@+id/surfaceview" android:layout_width="fill_parent" android:layout_height="fill_parent" /> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" > <Button android:id="@+id/bt_start" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="开始" android:onClick="start" android:layout_marginRight="10dp"/> <Button android:id="@+id/bt_stop" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="停止" android:onClick="stop" android:enabled="false" android:layout_marginRight="10dp"/> </LinearLayout> </RelativeLayout>
2、MainActivity
package com.njupt.vediorecorder; import java.io.File; import android.media.MediaRecorder; import android.os.Bundle; import android.os.Environment; import android.app.Activity; import android.view.Menu; import android.view.SurfaceHolder; import android.view.SurfaceView; import android.view.View; import android.widget.Button; public class MainActivity extends Activity { private SurfaceView surfaceview; private MediaRecorder mr; private Button bt_start; private Button bt_stop; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); surfaceview = (SurfaceView) findViewById(R.id.surfaceview); bt_start = (Button) findViewById(R.id.bt_start); bt_stop = (Button) findViewById(R.id.bt_stop); SurfaceHolder holder = surfaceview.getHolder(); holder.setFixedSize(176, 144); holder.setKeepScreenOn(true); holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } public void start(View v) { try { mr = new MediaRecorder(); mr.reset(); mr.setAudioSource(MediaRecorder.AudioSource.MIC); mr.setVideoSource(MediaRecorder.VideoSource.CAMERA); mr.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); mr.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); mr.setVideoEncoder(MediaRecorder.VideoEncoder.H264); File file = new File(Environment.getExternalStorageDirectory(), System.currentTimeMillis() + ".3gp"); mr.setOutputFile(file.getAbsolutePath()); mr.setPreviewDisplay(surfaceview.getHolder().getSurface()); mr.prepare(); bt_start.setEnabled(false); bt_stop.setEnabled(true); mr.start(); } catch (Exception e) { e.printStackTrace(); } } public void stop(View v){ mr.stop(); bt_start.setEnabled(true); bt_stop.setEnabled(false); mr.release(); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }
3、AndroidManifest.xml
注册权限
<uses-permission android:name="android.permission.RECORD_AUDIO"/>//媒体刻录 <uses-permission android:name="android.permission.CAMERA"/>//拍照 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>//以下两个是读写SD卡 <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
横屏显示
android:screenOrientation="landscape"
[3] makefile编纂差异
来源: 互联网 发布时间: 2014-02-18
makefile编写差异
由于zlib动态库在linux下引用的问题引出了对于简练的makefile的学习。之前通过看网络上的一些文章自己也算简单了解如何编写一个makefile,可总是不那么美观,今天经过辉哥的指点,对于makefile做了调整,看下两者之间的差别吧。如果有更好的方法,欢迎指点。
第一次文件如下:
CPP=filehead.cpp xmailuncompress.cpp zlibstrage.cpp compressfactory.cpp md5.cpp OBJ = md5.o compressfactory.o filehead.o xmailuncompress.o zlibstrage.o .PHONY:ALL ALL: libcompress.a libcompress.so onlyUncompress mytest HEAD = -I./include/ mytest: main.cpp g++ main.cpp -g -L. -lcompress -L./so/ -llogger ${HEAD} -I. -o $@ rm -f *.o onlyUncompress:unCompress.cpp g++ unCompress.cpp -g -L. -lcompress -L./so/ -llogger ${HEAD} -I. -o $@ libcompress.a:$(OBJ) ar -rc libcompress.a $(OBJ) libcompress.so:$(CPP) g++ -g -fPIC -shared -Wl,-rpath ./so/ -L./so -lz -llogger ${CPP} -o $@ ${HEAD} cp libcompress.so ./so/ compressfactory.o:compressfactory.cpp g++ -c compressfactory.cpp ${HEAD} filehead.o:filehead.cpp g++ -c filehead.cpp ${HEAD} xmailuncompress.o:xmailuncompress.cpp g++ -c xmailuncompress.cpp ${HEAD} zlibstrage.o:zlibstrage.cpp g++ -c zlibstrage.cpp -L./so -lz ${HEAD} md5.o:md5.cpp g++ -c md5.cpp ${HEAD} install: cp libcompress.so ../libcomp/so/ cp ./so/*.so ../libcomp/so/ cp *.h ../libcomp/include/ cp ./include/* ../libcomp/include/ cp *.h ../dfs_api/include/compress/ cp libcompress.so ../dfs_api/lib/ clean: rm -f *.o rm -f libcompress.a rm -f mytest rm -f onlyUncompress rm -f libcompress.so
经过修改后的makefile如下:
CPP=main.cpp filehead.cpp xmailuncompress.cpp zlibstrage.cpp compressfactory.cpp md5.cpp FLAG= -c -g -fPIC -shared OBJ=filehead.o xmailuncompress.o zlibstrage.o compressfactory.o md5.o .PHONY:ALL all:libcompress.a libcompress.so onlyUncompress mytest HEAD= -I./include/ -I. LIB= -L./ -llogger -lz mytest: main.o g++ $< -g -L. -lcompress ${LIB} ${HEAD} -I. -o $@ rm -f *.o onlyUncompress:unCompress.cpp g++ unCompress.cpp -g -L. -lcompress ${LIB} ${HEAD} -I. -o $@ libcompress.a:$(OBJ) ar -rc libcompress.a $(OBJ) libcompress.so:$(OBJ) g++ -g -fPIC -shared -Wl,-rpath ${LIB} $(OBJ) -o $@ ${HEAD} .cpp.o: g++ $(HEAD) $(FLAG) -o $@ $< install: cp libcompress.so ../libcomp/so/ cp *.so ../libcomp/so/ cp *.h ../libcomp/include/ cp ./include/* ../libcomp/include/ cp *.h ../dfs_api/include/compress/ cp libcompress.so ../dfs_api/lib/ clean: rm -f *.o rm -f libcompress.a rm -f mytest rm -f onlyUncompress rm -f libcompress.so
两者对比来看是不是后者清晰简练不少
顺带的了解了两个小的知识点:
在makefile中$>代表引用“:”后的内容,,,$@引用“:”前的内容
最新技术文章: