您的位置:首页 > 移动开发 > Android开发

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);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: