多功能记事本开发之路——01 界面布局篇

来源:互联网 发布:linux shell 设置变量 编辑:程序博客网 时间:2024/04/30 13:10


           



Android 自带的记事本功能有限对于我这个处女座的人来说这无疑是一种精神上的摧残。那我还是自己写一个记事本软件好了。这一次我不想做单纯的生成文本的功能,我想再次基础上加上一些扩展功能。具体功能整个布局的图片都可以看的到。 今天先来完成下界面布局吧。Android 的布局个人觉得还是很麻烦(至少比起JAVASE这是真的) 后期用到的数据库无非就是SQLite算是比较简单,但我尽力把这个APP做的人性化一些小细节觉得心情嘛。先来看一下整个软件的布局。

主布局:activity_main.xml

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"                android:layout_width="match_parent"                android:layout_height="match_parent"                android:background="@drawable/navigationbar_bg"        >    <TextView            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="hello world"            android:textColor="#000000"            /></RelativeLayout>


这个时候来重写一个title来替换掉原有的那个蹉B 

title_add .xml 

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                >    <ImageView            android:id="@+id/iv_icon"            android:layout_width="35dp"            android:layout_height="35dp"            android:src="@drawable/icon"            android:layout_margin="5dp"            android:layout_alignParentLeft="true"            />    <TextView            android:layout_width="wrap_content"            android:layout_height="35dp"            android:text="记事本"            android:layout_margin="5dp"            android:textSize="20dp"            android:gravity="center_vertical"            android:layout_toRightOf="@id/iv_icon"            />    <Button            android:id="@+id/bt_add"            android:layout_height="35dp"            android:layout_width="35dp"            android:background="@drawable/navigationbar_add"            android:layout_toLeftOf="@+id/bt_setting"            android:layout_margin="5dp"            />    <Button            android:id="@+id/bt_setting"            android:layout_height="35dp"            android:layout_width="35dp"            android:background="@drawable/navigationbar_setting"            android:layout_alignParentRight="true"            android:layout_margin="5dp"            /></RelativeLayout>



 item_button.xml这个是上述GridView中每一项布局文件:

<?xml version="1.0" encoding="utf-8"?>  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"      android:layout_width="match_parent"      android:layout_height="match_parent"      android:orientation="vertical" >      <ImageView           android:id="@+id/item_image"          android:layout_height="35dp"          android:layout_width="35dp"          android:layout_margin="5dp"          />      </RelativeLayout>  



然后替换掉Android自带的标题栏 (顺序不可错) 

requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);  setContentView(R.layout.activity_main);  getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_main);


 title_add2.xml 同样是添加记事界面的标题栏 只不过布局有所变化,在第二个界面中用到的是返回与确定 :


<?xml version="1.0" encoding="utf-8"?>  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"      android:layout_width="match_parent"      android:layout_height="45dp"       android:background="@drawable/navigationbar_bg">      <Button           android:id="@+id/bt_back"          android:layout_width="35dp"          android:layout_height="35dp"          android:background="@drawable/navigationbar_backup"          android:layout_margin="5dp"          android:layout_alignParentLeft="true"          />      <TextView           android:layout_width="wrap_content"          android:layout_height="35dp"          android:text="新增记事"          android:layout_margin="5dp"          android:textSize="20dp"          android:gravity="center_vertical"          android:layout_centerHorizontal="true"          />            <Button           android:id="@+id/bt_save"          android:layout_height="35dp"          android:layout_width="35dp"          android:background="@drawable/navigationbar_save"          android:layout_alignParentRight="true"          android:layout_margin="5dp"          />        </RelativeLayout>  

第二个界面一如既往的使用了一点也不Simple的SimpleAdapter,主要代码为:

不好意思,居然忘记用for循环,这把我敲的 (嘿嘿)

ArrayList<HashMap<String,Object>> imagelist = new ArrayList<HashMap<String,Object>>();HashMap<String,Object> map1 = new HashMap<String,Object>();  map1.put("image", R.drawable.tabbar_handwrite);  imagelist.add(map1);    HashMap<String,Object> map2 = new HashMap<String,Object>();  map2.put("image", R.drawable.tabbar_paint);  imagelist.add(map2);    HashMap<String,Object> map3 = new HashMap<String,Object>();  map3.put("image", R.drawable.tabbar_microphone);  imagelist.add(map3);    HashMap<String,Object> map4 = new HashMap<String,Object>();  map4.put("image", R.drawable.tabbar_photo);  imagelist.add(map4);    HashMap<String,Object> map5 = new HashMap<String,Object>();  map5.put("image", R.drawable.tabbar_camera);  imagelist.add(map5);    HashMap<String,Object> map6 = new HashMap<String,Object>();  map6.put("image", R.drawable.tabbar_appendix);  imagelist.add(map6);      SimpleAdapter simpleAdapter = new SimpleAdapter(this, imagelist, R.layout.item_button, new String[] {"image"}, new int[]{R.id.item_image});    // 设置GridView的适配器为新建的simpleAdapter  gridView.setAdapter(simpleAdapter);}


     到此上述界面已完成,下一节,实现添加相片功能 







0 0
原创粉丝点击