Android 基础

RelativeLayout是相对布局控件:以控件之间相对位置或相对父容器位置进行排列。

Android流式布局,支持单选、多选等,适合用于产品标签等。



//添加按钮事件 
b1.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				t1.setText("点击了按钮");
			}
		});


Android平台中音频播放主要有两种方式

1、SoundPool声音池----适合短促且对反应速度比较高的情况(游戏音效或按键声等)

2、MediaPlayer媒体媒体播放器----适合比较且对反应速度要求不高的情况(音乐等待)


设置全屏显示

      //设置无标题  
        requestWindowFeature(Window.FEATURE_NO_TITLE);  
        //设置全屏  
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,   
                WindowManager.LayoutParams.FLAG_FULLSCREEN);  



设置横屏

        if(getRequestedOrientation()!=ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE){
        	  setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        	 }
//        要设置成竖屏设置成 SCREEN_ORIENTATION_PORTRAIT

获取屏幕分辨率

        //获取手机分辨率
        DisplayMetrics dm = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(dm);
        String strOpt = "手机屏幕分辨率为  "+dm.widthPixels+" * " +dm.heightPixels;
        t.setText(strOpt);

设置布局背景

        LinearLayout myLayout = (LinearLayout) findViewById(R.id.linearLayout1);
       //设置布局背景
        myLayout.setBackgroundColor(Color.WHITE);


ImageView 图片标签

scaleType="fitCenter"
  <!-- 等比例缩放,并居中显示 -->   

scaleType="fitStart"
  <!-- 等比例缩放,并居上显示 -->   


scaleType="fitEnd" 
  <!-- 等比例缩放,并居下显示 -->   

scaleType="center"
  <!-- 如果图片大,选取中间部分显示->   



scaleType="centerInside"
  <!-- 如果图片大,缩小居中显示->   


 android:scaleType="centerCrop"
        /><!-- 把imageview填满 -->  

EditText标签设置输入类型(密码)

android:inputType="textPassword"


相对布局

<!-- 第一组相对布局 -->
       <!--  <TextView 
        android:id="@+id/firstView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#FF0000"
        android:text="第一个TextView"
        />
         <TextView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#00FF00"
        android:layout_toRightOf="@id/firstView"
        android:text="第二个TextView"
        />
          <TextView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#00FF00"
        android:layout_below="@id/firstView"
        android:text="第三个TextView"
        /> -->
        <!-- 第二种相对布局 -->
       <!--  <TextView 
        android:id="@+id/firstView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#FF0000"
        android:text="第一个TextView"
        />
         <TextView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#00FF00"
        android:layout_alignRight="@id/firstView"
        android:text="第二个Te"
        /> -->
        
        <!-- 对齐基准线 -->
        <!-- <TextView 
        android:id="@+id/firstView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#FF0000"
        android:textSize="50sp"
        android:text="hello World"
        />
         <TextView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#00FF00"
        android:layout_toRightOf="@id/firstView"
        android:layout_alignBaseline="@id/firstView"
        android:text="第二个Te"/> -->
        
        <!-- 与控控件边缘对齐 -->
      <!--   <TextView 
        android:id="@+id/firstView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#FF0000"
        android:textSize="50sp"
        android:layout_alignParentRight="true"
        android:layout_alignParentBottom="true"
        android:text="hello World"
        /> -->


		<!-- 对齐到父控件中央 -->
		<!-- <TextView 
        android:id="@+id/firstView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#FF0000"
        android:textSize="50sp"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="hello World"
        /> -->
        <!-- 新属性 layout_alignEnd="@id/firstView" -->
        <TextView 
        android:id="@+id/firstView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#FF0000"
        android:textSize="50sp"
        android:text="hello World"
        />
        
        <TextView 
        android:id="@+id/secondView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#00ff00"
        android:textSize="50sp"
		android:layout_below="@id/firstView"
        android:text="World"
        />
		

进度条

ProgressBar

进度条风格

 style="?android:attr/progressBarStyleHorizontal"

水平风格Horizontal

小风格Small

大风格Large

反向风格Inverse

小反向风格Small.Inverse

大反向风格Large.Inverse

   <ProgressBar 
        android:id="@+id/firstProgressBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:max="1000"
        android:progress="100"
        style="?android:attr/progressBarStyleHorizontal"
        />

        //以前进度基础上增加10
        progressbar.incrementProgressBy(10);
        //第二进度增加10
//        progressbar.incrementSecondaryProgressBy(10)

Activity生命周期

//当Activity对象被第一次创建时调用
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Toast.makeText(Activity_lifeActivity.this, "onCreate", Toast.LENGTH_SHORT).show();

    }
	//当前Activity被销毁之前将会调用该方法
	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		Toast.makeText(Activity_lifeActivity.this, "onDestroy", Toast.LENGTH_SHORT).show();
	}
	//当系统即将启动另外一个Activity之前调用该方法
	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		Toast.makeText(Activity_lifeActivity.this, "onPause", Toast.LENGTH_SHORT).show();
	}
//	当一个Activity再次启动之前调用该方法
	@Override
	protected void onRestart() {
		// TODO Auto-generated method stub
		super.onRestart();
		Toast.makeText(Activity_lifeActivity.this, "onRestart", Toast.LENGTH_SHORT).show();
	}
	//当Activity开始准备与用户交互时调用
	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		Toast.makeText(Activity_lifeActivity.this, "onResume", Toast.LENGTH_SHORT).show();
	}
	//当Activity变得可见时调用该函数
	@Override
	protected void onStart() {
		// TODO Auto-generated method stub
		super.onStart();
		Toast.makeText(Activity_lifeActivity.this, "onStart", Toast.LENGTH_SHORT).show();
	}
	//当前Activity变得不可见时调用
	@Override
	protected void onStop() {
		// TODO Auto-generated method stub
		super.onStop();
		Toast.makeText(Activity_lifeActivity.this, "onStop", Toast.LENGTH_SHORT).show();
	}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值