08-18 Activity跳转 Button LinearLayout布局 Relative属性
来源:互联网 发布:搭建网络视频直播 编辑:程序博客网 时间:2024/05/21 16:56
Activity跳转
![这里写图片描述](http://img.blog.csdn.net/20150818205036745)//**MainActivity**public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button btn=(Button)findViewById(R.id.button); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent=new Intent(getApplicationContext(),Second_Activity.class); startActivity(intent); } }); } @Override protected void onStart() { super.onStart(); Log.d("myApplication", "onStart "); } @Override protected void onRestart() { super.onRestart(); Log.d("myApplication", "onRestart"); } @Override protected void onResume() { super.onResume(); Log.d("myApplication", "onResume "); } @Override protected void onPause() { super.onPause(); Log.d("myApplication", "onPause "); } @Override protected void onStop() { super.onStop(); Log.d("myApplication", "onStop "); } @Override protected void onDestroy() { super.onDestroy(); Log.d("myApplication", "onDestroy "); }}//**Second_Activity**public class Second_Activity extends Activity{ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d("second_activity", "onCreate "); } @Override protected void onStart() { super.onStart(); Log.d("second_activity", "onStart "); } @Override protected void onResume() { super.onResume(); Log.d("second_activity", "onResume "); } @Override protected void onPause() { super.onPause(); Log.d("second_activity", "onPause "); } @Override protected void onStop() { super.onStop(); Log.d("second_activity", "onStop "); } @Override protected void onDestroy() { super.onDestroy(); Log.d("second_activity", "onDestroy "); }}//**activity_main**<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" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"> <TextView android:text="@string/hello_world" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/textView" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="第二个界面" android:id="@+id/button" android:layout_margin="@dimen/activity_horizontal_margin" /></RelativeLayout>//**layout_second**<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"></LinearLayout>//**AndroidManifest**<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.administrator.myapplication" > <application android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".Second_Activity"></activity> </application></manifest>
Button LinearLayout布局
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_weight="1" android:layout_height="0dip" android:orientation="horizontal"> <Button android:layout_width="0dip" android:layout_weight="1" android:layout_height="match_parent" /> <LinearLayout android:layout_width="0dip" android:layout_weight="2" android:layout_height="match_parent" android:orientation="vertical"> <Button android:layout_width="match_parent" android:layout_weight="1" android:layout_height="0dip" /> <Button android:layout_width="match_parent" android:layout_weight="1" android:layout_height="0dip" /> </LinearLayout> </LinearLayout> <Button android:layout_width="match_parent" android:layout_weight="1" android:layout_height="0dip" /> <LinearLayout android:layout_width="match_parent" android:layout_weight="1" android:layout_height="0dip" android:orientation="horizontal"> <LinearLayout android:layout_width="0dip" android:layout_weight="1" android:layout_height="match_parent" android:orientation="vertical"> <Button android:layout_width="match_parent" android:layout_weight="1" android:layout_height="0dip" /> <Button android:layout_width="match_parent" android:layout_weight="1" android:layout_height="0dip" /> <Button android:layout_width="match_parent" android:layout_weight="1" android:layout_height="0dip" /> </LinearLayout> <Button android:layout_width="0dip" android:layout_weight="2" android:layout_height="match_parent" /> </LinearLayout></LinearLayout>![这里写图片描述](http://img.blog.csdn.net/20150818200123407)
Relative属性
//**margin属性** 不需要加ID<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:id="@+id/button3" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentRight="true"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:layout_alignParentBottom="true"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:layout_alignParentRight="true"/></RelativeLayout>![这里写图片描述](http://img.blog.csdn.net/20150819194847046)//**gravity属性** 需要加ID<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <Button android:layout_width="150dp" android:layout_height="150dp" android:background="#ff0000" android:id="@+id/button" android:layout_centerVertical="true" android:layout_centerHorizontal="true" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toLeftOf="@id/button"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@id/button"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@id/button"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/button"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@id/button" android:layout_above="@id/button"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignRight="@id/button" android:layout_below="@id/button"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignRight="@id/button" android:layout_alignTop="@id/button"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@id/button" android:layout_alignBottom="@id/button"/></RelativeLayout>![这里写图片描述](http://img.blog.csdn.net/20150818200556857)
0 0
- 08-18 Activity跳转 Button LinearLayout布局 Relative属性
- 08-18 Activity跳转 Button LinearLayout布局 Relative属性
- Relative布局常用属性
- LinearLayout布局属性难点
- linearlayout线性布局属性
- LinearLayout布局属性
- Relative 布局的基本属性
- Activity布局之LinearLayout、RelativeLayout
- Android Activity布局之LinearLayout
- LinearLayout和Relative的属性与子属性的区别
- LinearLayout和Relative的属性与子属性的区别
- LinearLayout布局的layout_weight属性
- Android布局-LinearLayout属性详解
- 线性布局LinearLayout常用属性
- Android LinearLayout线性布局属性
- LinearLayout布局下Button按钮不可见
- LinearLayout/RelativeLayout/FrameLayout实例,以及Activity跳转
- Relative布局中的各个属性的含义
- sql
- VBScript random function
- 08-13 登录、注册, 数据库连接
- 求一个小于10的正整数的n次方,n很大
- BloomFilter 布隆过滤
- 08-18 Activity跳转 Button LinearLayout布局 Relative属性
- HDU 5378(Leader in Tree Land-利用概率dp)
- Java学习之自动装箱和自动拆箱源码分析
- 代码规范若干建议
- HEXO+Github,搭建自己的博客,最新版HEXO配置
- iOS开发系列--地图与定位
- 初识SVN
- CentOS学习3_CentOS6.5下安装Eclipse
- “调试器的协议与调试对象不兼容”错误的解决