Android快速开发(1)
2016-02-14 16:32
447 查看
1.activity相互调用
2.相对布局
3.android mainifest application theme
4.创建菜单,并响应动作
5.通知:toast
6.layout
1)fill_parent
设置一个构件的布局为fill_parent将强制性地使构件扩展,以填充布局单元内尽可能多的空间。这跟Windows控件的dockstyle属性大体一致。设置一个顶部布局或控件为fill_parent将强制性让它布满整个屏幕。
2) wrap_content
设置一个视图的尺寸为wrap_content将强制性地使视图扩展以显示全部内容。以TextView和ImageView控件为例,设置为wrap_content将完整显示其内部的文本和图像。布局元素将根据内容更改大小。设置一个视图的尺寸为wrap_content大体等同于设置Windows控件的Autosize属性为True。
3)match_parent
Android2.2中match_parent和fill_parent是一个意思 .两个参数意思一样,match_parent更贴切,于是从2.2开始两个词都可以用。那么如果考虑低版本的使用情况你就需要用fill_parent了。
logo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent("com.example.think.myapplication.DetailActivity")); } });
<activity android:name=".DetailActivity" android:label="@string/title_activity_detail" android:theme="@style/AppTheme"> <intent-filter> <action android:name="com.example.think.myapplication.DetailActivity"/> <category android:name="android.intent.category.DEFAULT"/> </intent-filter> </activity>
2.相对布局
<?xml version="1.0" encoding="utf-8"?> <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" tools:context="com.example.think.myapplication.MainActivity"> <RelativeLayout android:layout_width="match_parent" android:layout_height="50dp" android:layout_alignParentTop="true" android:id="@+id/relativeLayout"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_centerVertical="true" android:layout_marginLeft="10dp" android:text="校内" android:textColor="#ee0b0b0b" android:textSize="18sp" android:id="@+id/textView" /> </RelativeLayout> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="300dp" android:id="@+id/linearLayout1" android:layout_below="@+id/relativeLayout" android:layout_above="@+id/main_bottom" android:layout_alignParentEnd="true"> </LinearLayout> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="54dp" android:background="#ffffff" android:gravity="center_vertical" android:id="@+id/main_bottom" android:layout_alignParentBottom="true"> <RelativeLayout android:id="@+id/re_weixin" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:onClick="onTabClicked" android:padding="3dp" > <ImageView android:id="@+id/ib_weixin" android:layout_width="wrap_content" android:layout_height="28dp" android:layout_centerHorizontal="true" android:background="#ffffff" android:focusable="false" android:scaleType="centerInside" android:src="@mipmap/weixin_normal" /> <TextView android:id="@+id/tv_weixin" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/ib_weixin" android:layout_centerHorizontal="true" android:layout_marginTop="3dp" android:text="消息" android:textColor="#9A9A9A" android:textSize="12sp" /> <TextView android:id="@+id/unread_msg_number" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_marginRight="10dp" android:gravity="center" android:text="7" android:textColor="@android:color/white" android:textSize="12sp" /> </RelativeLayout> <RelativeLayout android:id="@+id/re_contact_list" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:onClick="onTabClicked" android:padding="3dp" > <ImageView android:id="@+id/ib_contact_list" android:layout_width="wrap_content" android:layout_height="28dp" android:layout_centerHorizontal="true" android:background="#ffffff" android:focusable="false" android:scaleType="centerInside" android:src="@mipmap/contact_list_normal" /> <TextView android:id="@+id/tv_contact_list" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/ib_contact_list" android:layout_centerHorizontal="true" android:layout_marginTop="3dp" android:text="通讯录" android:textColor="#9A9A9A" android:textSize="12sp" /> <TextView android:id="@+id/unread_address_number" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_marginRight="10dp" android:gravity="center" android:text="7" android:textColor="@android:color/white" android:textSize="12sp" /> </RelativeLayout> <RelativeLayout android:id="@+id/re_find" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:onClick="onTabClicked" android:padding="3dp" > <ImageView android:id="@+id/ib_find" android:layout_width="wrap_content" android:layout_height="28dp" android:layout_centerHorizontal="true" android:background="#ffffff" android:focusable="false" android:scaleType="centerInside" android:src="@mipmap/find_normal" /> <TextView android:id="@+id/tv_find" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/ib_find" android:layout_centerHorizontal="true" android:layout_marginTop="3dp" android:text="发现" android:textColor="#9A9A9A" android:textSize="12sp" /> </RelativeLayout> <RelativeLayout android:id="@+id/re_profile" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:onClick="onTabClicked" android:padding="3dp" > <ImageView android:id="@+id/ib_profile" android:layout_width="wrap_content" android:layout_height="28dp" android:layout_centerHorizontal="true" android:background="#ffffff" android:focusable="false" android:scaleType="centerInside" android:src="@mipmap/profile_normal" /> <TextView android:id="@+id/tv_profile" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/ib_profile" android:layout_centerHorizontal="true" android:layout_marginTop="3dp" android:text="我" android:textColor="#9A9A9A" android:textSize="12sp" /> </RelativeLayout> </LinearLayout> <View android:id="@+id/view_temp" android:layout_width="match_parent" android:layout_height="0.1dp" android:layout_above="@id/main_bottom" android:background="#d6d6d6" /> <RelativeLayout android:id="@+id/fragment_container" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_above="@id/view_temp" /> </RelativeLayout>
3.android mainifest application theme
转自http://blog.csdn.net/feng88724/article/details/6457431 •android:theme="@android:style/Theme.Dialog" 将一个Activity显示为能话框模式 •android:theme="@android:style/Theme.NoTitleBar" 不显示应用程序标题栏 •android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 不显示应用程序标题栏,并全屏 •android:theme="Theme.Light" 背景为白色 •android:theme="Theme.Light.NoTitleBar" 白色背景并无标题栏 •android:theme="Theme.Light.NoTitleBar.Fullscreen" 白色背景,无标题栏,全屏 •android:theme="Theme.Black" 背景黑色 •android:theme="Theme.Black.NoTitleBar" 黑色背景并无标题栏 •android:theme="Theme.Black.NoTitleBar.Fullscreen" 黑色背景,无标题栏,全屏 •android:theme="Theme.Wallpaper" 用系统桌面为应用程序背景 •android:theme="Theme.Wallpaper.NoTitleBar" 用系统桌面为应用程序背景,且无标题栏 •android:theme="Theme.Wallpaper.NoTitleBar.Fullscreen" 用系统桌面为应用程序背景,无标题栏,全屏 •android:theme="Translucent" 半透明 •android:theme="Theme.Translucent.NoTitleBar" 半透明、无标题栏 •android:theme="Theme.Translucent.NoTitleBar.Fullscreen" 半透明、无标题栏、全屏 •android:theme="Theme.Panel" •android:theme="Theme.Light.Panel"
4.创建菜单,并响应动作
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. //创建右上角菜单 menu.add(1, RED, 0, "红色"); menu.add(1, GREEN, 1, "绿色"); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { int itemId = item.getItemId(); switch (itemId) { case RED: new AlertDialog.Builder(MainActivity.this).setTitle("hi") .setMessage("red") .setPositiveButton("ok", null).show(); break; case GREEN: new AlertDialog.Builder(MainActivity.this).setTitle("hi") .setMessage("green") .setPositiveButton("ok", null).show(); break; } return true; }
5.通知:toast
Toast.makeText(MainActivity.this, R.string.success, Toast.LENGTH_SHORT).show();
6.layout
1)fill_parent
设置一个构件的布局为fill_parent将强制性地使构件扩展,以填充布局单元内尽可能多的空间。这跟Windows控件的dockstyle属性大体一致。设置一个顶部布局或控件为fill_parent将强制性让它布满整个屏幕。
2) wrap_content
设置一个视图的尺寸为wrap_content将强制性地使视图扩展以显示全部内容。以TextView和ImageView控件为例,设置为wrap_content将完整显示其内部的文本和图像。布局元素将根据内容更改大小。设置一个视图的尺寸为wrap_content大体等同于设置Windows控件的Autosize属性为True。
3)match_parent
Android2.2中match_parent和fill_parent是一个意思 .两个参数意思一样,match_parent更贴切,于是从2.2开始两个词都可以用。那么如果考虑低版本的使用情况你就需要用fill_parent了。
相关文章推荐
- android studio NDK编程
- IIS7上设置MIME让其支持android和Iphone的更新下载
- Xamarin.Android 如何使用圆形Image
- android 自带图库
- Android开发中一些被冷落但却很有用的类和方法
- android 开发 命名规范
- Android琐碎知识点,不断更新中
- Android开发:Translucent System Bar 的最佳实践
- Android之RecyclerView简单使用(二)
- Android JSON解析
- Android消息处理系统原理简要概述
- ANDROID_MARS学习笔记_S01原始版_009_下载文件
- Android电话事件案例
- android开发中英文切换
- android:giavity和layout_gravity的区别
- Android类参考---Fragment
- 让动画不再僵硬:Facebook Rebound Android动画库介绍
- 看Android开发笔记之:消息循环与Looper的详解有感
- Android 接入支付宝支付只需十分钟
- Android Studio发布项目到jcenter升级版