FrameLayout
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_width="243dp"
android:layout_height="210dp"
android:id="@+id/button2"
android:layout_gravity="left|top" />
<Button
android:layout_width="193dp"
android:layout_height="152dp"
android:id="@+id/button3"
android:layout_gravity="left|top" />
</FrameLayout>
TableLayout
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="0,1,2"//下标从0开始
android:shrinkColumns="3,4">//可伸缩的列
<TableRow>
<Button android:text="1"/>
<Button android:text="2"/>
<Button android:text="3"/>
</TableRow>
<TableRow>
<Button android:text="11"/>
<Button android:text="22"/>
<Button android:text="33"/>
</TableRow>
<TableRow>
<Button android:text="111"/>
<Button android:text="222"/>
<Button android:text="333"/>
</TableRow>
</TableLayout>
TableLayout的属性:
strechColumns 占用剩余空间(设置可伸展的列)
collapseColumns 隐藏某一列
shrinkColumns 设置可收缩的列
visibility(在界面中)
android:visibility="gone"//不显示,不占空间
android:visibility="visible"//显示
android:visibility="invisible"//不显示,但占空间
启动Activity
1.直接启动Activity
Intent intent=new Intent(MainActivity.this,SecondActivity.class)
startActivity(intent);
2.带有返回值的启动方式
(1)第一个界面调用startActivityForResult(intent,requestCode); 例:startActivityForResult(intent,0x23)
(2)第二个界面先调用getIntent()得到启动的intent,在关闭第二个界面前先封装数据intent.putExtra(“secondbackdata”,editText().toString());
(3)设置resultCode :setResult(RESULT_OK,intent)
(4)关闭第二个界面:SecondActivity.this.finish()
(5)第一个界面准备接受数据:
重写onActivityResult(requestCode,resultCode,Intent data);
判断resultCode;
然后从data中取出数据
MainActivity中
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(resultCode==RESULT_OK){
String s=data.getStringExtra("key");
textView.setText(s);
}
}
SecondActivity中
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
intent= getIntent();
intent.putExtra("key", editText.getText().toString());
setResult(RESULT_OK,intent);
SecondActivity.this.finish();
}
});
去掉标题、信息栏,必须写在setContentview()前面
this.requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);//去掉信息栏
screenORientation="portrait"(设置竖屏)
screenOrientation="landscape"(设置横屏)
Android四大组件(五大组件Intent)
Activity、Service、ContentProvider、BroadcastReceive
Intent:Android通讯的
属性:action、component、data、category、type、extra
action(拨打电话、发信息、打开网页)
package com.example.administrator.myapplication;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
/**
* Created by Administrator on 2015/8/19.
*/
public class IntentActivity extends Activity {
private Button mButtonPhone;
private Button mButtonCall;
private Button mButtonSms;
private Button mButtonWeb;
private Button mButtonHide;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.intent_layout);
mButtonPhone=(Button)findViewById(R.id.button_phone);
mButtonPhone.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent();
intent.setAction(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:18500292306"));
startActivity(intent);
}
});
mButtonCall=(Button)findViewById(R.id.button_call);
mButtonCall.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:18500292306"));
startActivity(intent);
}
});
mButtonSms=(Button)findViewById(R.id.button_sms);
mButtonSms.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent(Intent.ACTION_SENDTO); intent.setData(Uri.parse("smsto:18500292306"));
intent.putExtra("sms_body","The SMS Text");
startActivity(intent);
}
});
mButtonWeb=(Button)findViewById(R.id.button_web);
mButtonWeb.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("http://www.baidu.com"));
startActivity(intent);
}
});
//隐式启动
mButtonHide=(Button)findViewById(R.id.button_hide);
mButtonHide.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent("com.example.administrator.myapplication");
startActivity(intent);
}
});
}
}
隐式启动Activity
<intent-filter>
<action android:name="com.example.administrator.myapplication"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
mButton5=(Button)findViewById(R.id.button_hide);
mButton5.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent("com.example.administrator.myapplication");
startActivity(intent);
}
});
隐式启动MainActivity并获取信息
IntentActivity中:
mButtonHide=(Button)findViewById(R.id.button_hide);
mEditText=(EditText)findViewById(R.id.editText);
mButtonHide.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent("com.example.administrator.myapplication");
String s=mEditText.getText().toString();
intent.putExtra("key",s);
startActivity(intent);
}
});
MainActivity中:
textView=(TextView)findViewById(R.id.textView);
intent=getIntent();
textView.setText(intent.getStringExtra("key"));