注意:控件显示一定要有宽高 ,否则就不会显示  layout_widthlayout_height     layout_height


Textview    文本框

id:控件身份标识     android:id="@+id/textView1"

xml:

android:textColor="@android:color/holo_purple"

code:


Button    继承TextView

事件点击  

xml:

 android:onClick="btn"


多个button设置监听   Activity  implement   OnclickLisenter



EditText  编辑框

android:hint="提示信息"

android:ems="10" 设置每行的文本长度

 获取焦点


code:

获得编辑内容

//获得编辑内容

String string = mEdit.getText().toString().trim();


ImageView

xml:

前景图片

 android:src="@drawable/ic_launcher"

背景图片

 android:background="@drawable/ic_launcher"

  android:scaleType="fitXY"   根据控件大小拉伸

code:

ImageButton    继承ImageView   点击事件


布局

warp_content 适应内容

march_Parent 填充父类容器   fill_Parent

单位:  尺寸单位:dp   字体:sp


pading   : 内容跟控件的距离


 android:paddingLeft="40dp"

android:paddingRight="40dp"

android:paddingTop="40dp"

android:paddingBottom="40dp"


margen: 控件跟控件的距离

android:layout_marginLeft="20dp"

android:layout_marginTop="20dp"

android:layout_marginRight="20dp"

android:layout_marginBottom="20dp"



线性布局  linearLayout

android:orientation="vertical"  垂直     "horizontal"  水平

 android:layout_weight="1"   权重   瓜分剩余空间

 android:gravity="left"   内容在控件中的位置


设置控件在布局中的位置

horizontal:  设置 垂直方向 控件的位置

android:layout_gravity="center_vertical"  布局中垂直居中

android:layout_gravity="bottom" 居于布局底部

android:layout_gravity="top"  居于布局顶部

vertical:  设置 水平方向 控件的位置

android:layout_gravity="center_horizontal"

android:layout_gravity="left" 居于布局左边

android:layout_gravity="right"  居于布局右边


相对布局   RelativeLayout


控件跟控件位置关系

android:layout_toRightOf="@+id/button1"

android:layout_toLeftOf="@+id/button1"

 android:layout_below="@+id/button1"

android:layout_above="@+id/button1"

控件跟控件之间的对齐   (基准线)

android:layout_alignBottom="@+id/button1"

android:layout_alignLeft="@+id/button1"

android:layout_alignTop="@+id/button1"

android:layout_alignBottom="@+id/button1"


控件跟布局位置关系

android:layout_alignParentLeft="true"

android:layout_alignParentRight="true"

android:layout_alignParentTop="true"

android:layout_alignParentBottom="true"

android:layout_centerHorizontal="true"  水平居中

android:layout_centerVertical="true"   垂直居中

android:layout_centerInParent="true"  居中


Intent 意图

连接四大组件之间的桥梁   

传递数据   

显示意图:  指明跳转方向

隐式意图: 打开符合过滤条件的界面


Activity :用于与用户进行交互   四大组件之一

创建要素:

1.创建类继承Acitvity

2.setContentView() 关联布局

3.在Manifest.xml 清单文件中注册


界面跳转:

A-->B

A:

        Intent intent=new Intent();

        //指明跳转方向

        intent.setClass(this, BActivity.class);

        intent.putExtra("name", "name");

        startActivity(intent);

B:

Intent intent = getIntent();

String stringExtra = intent.getStringExtra("name");

A--->B--->A


请求码   区分请求事件                                      

requestCode


结果码    区分返回的信息

resultCode     



Serveice  服务     四大组件之一

没有界面  长期运行在后台

应用场景: 下载   音乐播放器

创建:


1.创建类继承Service

2.在清单文件中进行注册


生命周期


1.启动服务方式一

startService

创建到运行

oncreat() ---->onStartCommand()

运行到销毁   stopService()

onDestroy


注意:

1.通过startService()启动的服务,只能通过 stopService()停止服务

2.通过startService()启动的服务,跟Acitivity的关系不密切,即时界面关闭(销毁)服务还在

3.服务启动过一次后,在启动,不会调用oncreat() ,只会调用onStartCommand(),服务只创建一次


自动导包 :ctrl +shift+o

 

方式二:

绑定服务 binderService

1.绑定

private ServiceConnection conn = new ServiceConnection() {

        @Override

        public void onServiceDisconnected(ComponentName name) {

            // 服务绑定失败时调用

        }

        @Override

        public void onServiceConnected(ComponentName name, IBinder service) {

            // 服务绑定成功时调用

        }

    };

2.解绑


创建到运行

oncreat()---->onBind()

运行---->销毁

onUnBind --->onDestory()

注意

binderService启动的服务,跟Activity关系密切,界面销毁,

服务也会销毁。



通过绑定服务得到服务中的消息

1.在Service中声明MyBinder类继承 Binder{}

2.MyBinder类自定义需要调用的方法

3.onBind() 创建一个MyBinder类型的对象并返回它

返回非空的实现IBinder接口的对象


Activity

4.服务绑定成功后

1.在onServiceConnected()获得onBind()返回的实现IBinder接口的对象索引,

2.调用自定义类里方法就需要IBinder接口的对象索引强制为MyBinder

    @Override

        public void onServiceConnected(ComponentName name, IBinder service) {

            // 服务绑定成功时调用

            MyBinder mbinder=(MyBinder) service;

            mTv.setText(mbinder.getPlayInfo());

            mTv2.setText(mbinder.getStopInfo());

        }


StartService 跟BindService   结合使用

 问题:

方法没有找到    确认 方法名没有写错


更多相关文章

  1. Android RelativeLayout布局的相对布局
  2. android-RelativeLayout实现顶部、中部、底部布局
  3. android 开发-spinner下拉框控件的实现
  4. 安卓 相对布局属性大全
  5. Android基本控件常用属性及方法
  6. Android UI控件学习笔记(二)
  7. android相对布局(RelativeLayout)属性整理
  8. Android按钮控件之RadioGroup和RadioButton
  9. android 布局文件中xmlns:android="http://schemas.android.com/

随机推荐

  1. Android File Hierarchy : System Struct
  2. [日更-2019.5.21] Android(安卓)系统的分
  3. android项目案例5- 基于Android studio的
  4. android databinding的使用技巧
  5. android 横竖屏锁定
  6. Relative Layout 中用到的一些属性
  7. View有关基础
  8. Android(安卓)UI控件之ListView实现圆角
  9. 指纹支付相关的细节处理
  10. android api 中文 (73)—— AdapterView