安装略…
1.android 常用单位
- px=像素
- dp=虚拟像素,在不同的像素密度的设备上会自动适配,推荐使用
- sp=同dp相似,主要用来显示文字,还会根据用户的字体大小偏好来缩放
2.match_parent、fill_parent、wrap_content区别
3.相对布局子控件属性
4.页面跳转+页面传参+接收到参数后显示到页面
主页
package com.example.myapplicationdemo1;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn= findViewById(R.id.lineLaout);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i=new Intent();
i.setClass(MainActivity.this,test.class);
i.putExtra("name","张三");
Bundle bundle=new Bundle();
bundle.putString("name2","王五");
bundle.putInt("id",12);
i.putExtras(bundle);
startActivity(i);
}
});
}
public void select(View view){
Toast.makeText(this,"按钮被点击啦",Toast.LENGTH_LONG).show();
}
}
跳转页test
package com.example.myapplicationdemo1;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
public class test extends AppCompatActivity {
private String data;
private Integer id;
private String name;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
Intent i=this.getIntent();
Bundle bundle=this.getIntent().getExtras();
data=i.getStringExtra("name");
name=bundle.getString("name2");
id=bundle.getInt("id");
TextView textView=findViewById(R.id.text1);
textView.setText("我的名字叫:"+data+",id是:"+id);
System.out.println("===================name>"+data);
System.out.println("===================name>"+name+","+id);
}
}