Android基础
2016-05-07 20:24
399 查看
用Android studio学Android
1.新建项目File->new->new project,注意路径、名称一律不能用汉字,中间不能有空格。
2.认识目录结构, 见图片:文档结构说明.png
3.视图view和布局layout文件的关系:
1)视图是放在布局之中。
2)布局转换为视图
视图转化为布局
4.新建XML文件并命名,采用需要的layout和button。
5.获取layout和button需要在XML文件中加id。里边格式如下:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/rl_root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/butn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="我是按钮呀"/>
</RelativeLayout>
在Javaclass中获取layout和button
通过id获取布局,但findViewById()返回的是View类型需要强制类型转换。
rl_root = (RelativeLayout) findViewById(R.id.rl_root);
butn = (Button) findViewById(R.id.butn);
布局转换为视图
View view= this.getLayoutInflater().inflate(R.layout.activity_splash,null);
1.新建项目File->new->new project,注意路径、名称一律不能用汉字,中间不能有空格。
2.认识目录结构, 见图片:文档结构说明.png
3.视图view和布局layout文件的关系:
1)视图是放在布局之中。
2)布局转换为视图
视图转化为布局
4.新建XML文件并命名,采用需要的layout和button。
5.获取layout和button需要在XML文件中加id。里边格式如下:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/rl_root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/butn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="我是按钮呀"/>
</RelativeLayout>
在Javaclass中获取layout和button
通过id获取布局,但findViewById()返回的是View类型需要强制类型转换。
rl_root = (RelativeLayout) findViewById(R.id.rl_root);
butn = (Button) findViewById(R.id.butn);
布局转换为视图
View view= this.getLayoutInflater().inflate(R.layout.activity_splash,null);
相关文章推荐
- Android 图片弹跳动画
- android基础--tools:context=".MainActivity"作用
- Android阴影背景
- Android实现点击两次返回键退出
- android挂断电话的功能
- Android 5.0 Lollipop 短彩信接收流程
- Android中常见的XML解析方式
- Android基础知识点总结
- Android Calender显示日期与时间
- Android之Camera介绍
- android studio使用.gitignore建立项目过滤规则
- Android 异步加载图像优化,如:引入线程池、引入缓存
- 四种方式写按钮点击事件和Android 中常用的布局
- 解决了在Android原生TextView中,当text长度小于hint时,TextView右方会占据多余的位置
- Android中 int,float,Double,String 互相转换
- 安卓反编译工具的应用
- ubuntu 编译vlc android 总结
- Ubuntu Android Studio不能输入中文的解决方案
- 关于Android的不同分辨率图片适配
- Android清理内存