如果已经用Android Studio打开过项目,点击File==>New Project新建项目
都填完之后 点击 finish 完成创建
Android Studio使用Gradle 编译运行Android工程,工程的每个模块以及整个工程都有一个build.gradle文件。通常你只需要关注模块的build.gradle文件,该文件存放编译依赖设置,包括defaultConfig设置:
创建一个 AVD:
Android Studio在运行程序:选择创建好的模拟器,点击ok
2 . 开启设备上的USB调试选项
在大部分运行Andriod3.2或更老版本系统的设备上,这个选项位于“设置>应用程序>开发选项”里,
在Andriod 4.0或更新版本中,这个选项在“设置>开发人员选项”里(从Android4.2开始,开发人员选项在默认情况下是隐藏的,想让它可见,可以去设置>关于手机(或者关于设备)点击版本号七次。再返回就能找到开发人员选项了。)
Android的图形用户界面是由多个View和ViewGroup构建出来的。View是通用的UI窗体小组件,比如按钮(Button)或者文本框(text field),而ViewGroup是不可见的用于定义子View布局方式的容器,比如网格部件(grid)和垂直列表部件(list)
Android提供了一个对应于View和ViewGroup子类的一系列XMl标签,你可以在XML里使用层级视图元素创建自己的UI,Layouts是ViewGroup的子类,接下来的练习将使用LinearLayout
关于viewgroup对象如何组织布局分支和包含其他view对象。可选的布局文件:在XML中定义界面布局而不是在运行时去动态生成布局是有多个原因的,其中最重要的一个原因是这样可以使得你为不同大小的屏幕创建不同的布局文件。例如,你可以创建创建2个版本的布局文件,告诉系统在小的
屏幕上使用其中一个布局文件,在大的屏幕上使用另外一个布局文件。
<LinearLayout 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:orientation="horizontal" >
</LinearLayout>
LinearLayout是ViewGroup的一个子类,用于放置水平或者垂直放置子视图的部件,由属性 android:orientation 来设定方向。LinearLayout里的子布局按照XML里定义的顺序向显示在屏幕上
另外的两个属性android:layout_width和android:layout_height,对于所有的Views都需要对这两个属性进行设置来指定尺寸
因为LinearLayout是整个视图的根布局,所以对于宽和高都应该是充满整个屏幕的,通过指定width 和 height属性
为 "match_parent" 。该值表示子View扩张自己width和height来匹配父控件的width和height
与其它View一样,你需要设置XML里的某些属性来指定EditText的属性值,下边是你应该在线性布局里指定的一些属性元素
该字符串资源与id使用了相同的名称(edit_message)。然而,对于资源的引用是区分类型的(比如id和字符
串),因此,使用相同的名称不会引起冲突
<EditText
android:id="@+id/edit_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="@string/edit_message" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_send" />
可以根据每一个部件所占的空间来指定权重值的大小,它的总数是有同级别的部件来决定的。就类似于饮料的成分配方:“两份伏特加酒,一份咖啡利口酒”,意思就是这个酒中伏特加酒占三分之二。例如,你设置一个View的权重是2,另一个View的权重是1,那么总数就是3,这时第一个View占据2/3的空间,第二个占据1/3的空间。如果你再加入第三个View,权重设为1,那么第一个View(权重为2的)会占据1/2的空间,剩余的另外两个View各占1/4。(请注意,使用权重的前提一般是给View的宽或者高的大小设置为0dp,然后系统根据上面的权重规则来计算View应该占据的空间。但是很多情况下,如果给View设置了match_parent的属性,那么上面计算权重时则不是通常的正比,而是反比,也就是权重值大的反而占据空间小)
<EditText
android:id="@+id/edit_message"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="@string/edit_message" />
<?xml version="1.0" encoding="utf-8"?><!--<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"--><!--xmlns:app="http://schemas.android.com/apk/res-auto"--><!--xmlns:tools="http://schemas.android.com/tools"--><!--android:layout_width="match_parent"--><!--android:layout_height="match_parent"--><!--tools:context=".MainActivity">-->
<LinearLayout 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:orientation="horizontal">
<EditText
android:id="@+id/edit_message"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="@string/edit_message" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_send" />
</LinearLayout>
原文:https://www.cnblogs.com/xiaoxiaoliu/p/10999567.html