JDK环境变量配置,studio安装。RelativeLayout和LinearLayout

来源:互联网 发布:sql server 2000数据库 编辑:程序博客网 时间:2024/05/24 03:15

jdk安装

首先,下载jdk,这里有官网网址,注意是哪个版本的,我的是window7 64位的,{http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html}

接下来安装时注意jdk和jre是两个文件夹,安装时建议所有出现路径的地方都选择默认路径(这样可以避免两者混乱),安装完成后应该是这样的两个文件夹
这里写图片描述

jdk环境变量配置

打开我的电脑右键属性》高级系统设置》环境变量》
这里写图片描述

1.系统变量→新建 JAVA_HOME 变量 。
变量值填写jdk的安装目录(本人是 E:\Java\jdk1.7.0)
2.系统变量→寻找 Path 变量→编辑
在变量值最后输入 %JAVA_HOME%\bin;%JAVA_HOME%\jre\bin;
(注意原来Path的变量值末尾有没有;号,如果没有,先输入;号再输入上面的代码)
3.系统变量→新建 CLASSPATH 变量
变量值填写 .;%JAVA_HOME%\lib;%JAVA_HOME%\lib\tools.jar(注意最前面有一点)
系统变量配置完毕

检验是否配置成功 运行cmd 输入 java -version (java 和 -version 之间有空格)
若如图所示 显示版本信息 则说明安装和配置成功。
这里写图片描述

studio的安装

问题一:在安装android studio时,可能机器出现安装问题:安装过程中弹出提示:

这里写图片描述
如果点击确定也可以打开,但是在关闭studio再次启动时就会打不开了,你可能觉得重装一次就可以了,但是重装并不能解决这个问题。那么,说一下解决办法:
首先在重启过程中进入bios状态,切换到Configuration选项,将设置Intel Virtual Technology=Enable;保存并退出,然后重新安装android studio即可。
这里写图片描述
这里写图片描述

问题二:安装完成后,弹出提示:

'msiexec'不是内部或外部命令,也不是可运行的程序或批处理文件。Failed to install Intel HAXM. For details, please check the installation log:"C:\Users\ADMINI~1\AppDate\Local\Temp\nsn9E04.tmp\haxm_silent_run.log"

这是环境变量配置的问题。大家都知道,所有windows下的cmd命令都是可执行程序(.exe)或批处理(.bat)文件,既然提示‘reg’不是…那么,肯定是没找到了。那么’reg’是在哪呢?它在:C:\Windows\System32下,名字就叫reg.exe;当然,msiexec也在这里面。那么解决办法就很简单了,在环境变量里添加它就OK。

path里添加:%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;当然,我之所以出现这个错误,估计是当初配置java环境的时候不小心把它干掉了,所以在之前配置环境变量是path原先的东西不要删除,在原来后面加;号,然后添加就行了!

创建第一个Android程序

安装完android studio后新建new project

1、在app中找到src→main→java和res→ layout以及AndroidManifest.xml
这些里面有我们主要关注的信息。
2、在activity_main.xml中创建TextView

 <TextView            android:id="@+id/text1"            android:layout_width="match_parent"            android:layout_height="match_parent"            android:gravity="center"            android:text="神爱世人"            android:textColor="#e00"//字体颜色设为红色            android:textSize="70dp" />

在这里文本内容直接写出:text=”神爱世人”,那么在mainactivity.java中就不需要找到文件的地址 :TextView tv = (TextView)findViewById(R.id.text1);
第二种方法是在textview中不写内容,这样写: android:text=”@string/hello_world”,然后再在res→values找到strings.xml,然后找到 神爱世人!,输入文本“神爱世人”,在mainactivity.java中要有TextView tv = (TextView)findViewById(R.id.text1); 。

线性布局和相对布局

android:orientation=”vertical” 竖直方向排列
horizontal 水平方向排列
layout_width宽度
layout_height高度
layout_weight按比例分布
相对布局(RelativeLayout)
这里写图片描述

显示这个界面

这里写图片描述
分析
1.从全局看整个屏幕是分为竖直排列的LinearLayout ,分为三部分:上面和下面是LinearLayout ,中间是一个Button.
2.上面的LinearLayout 又分成水平排列的两部分,右边是一个Button,左边又是一个LinearLayout ,这个LinearLayout 又是竖直排列的两部分。
3.下面的LinearLayout 先分为水平分布的两部分,左边是一个LinearLayout ,这个LinearLayout 又是竖直分布的三部分。右边是一个Button.

代码如下:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical"//整体的分布是竖直方向的    ><LinearLayout//这个是上面的LinearLayout ,它的宽度充满屏幕,高度占整个屏幕的1/3,它包括一个Button和另一个LinearLayout     android:layout_width="match_parent"    android:layout_height="0dip"    android:layout_weight="1"    android:orientation="horizontal">//这个LinearLayout 是水平分布的    <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_height="0dip"            android:layout_weight="1"/>        <Button            android:layout_width="match_parent"            android:layout_height="0dip"            android:layout_weight="1"/>    </LinearLayout>   </LinearLayout>    <Button        android:layout_width="match_parent"        android:layout_height="0dip"        android:layout_weight="1"/><LinearLayout    android:layout_width="match_parent"    android:layout_height="0dip"    android:layout_weight="1"    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_height="0dip"          android:layout_weight="1"/>        <Button            android:layout_width="match_parent"            android:layout_height="0dip"            android:layout_weight="1"/>        <Button            android:layout_width="match_parent"            android:layout_height="0dip"            android:layout_weight="1"/>    </LinearLayout>    <Button        android:layout_width="0dip"       android:layout_weight="1"        android:layout_height="match_parent" /></LinearLayout></LinearLayout>

相对布局和绝对布局的嵌套

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:gravity="center"    android:orientation="vertical">    <LinearLayout        android:layout_width="match_parent"        android:layout_height="0dip"        android:layout_weight="1">        <TextView            android:id="@+id/text1"            android:layout_width="match_parent"            android:layout_height="match_parent"            android:gravity="center"            android:text="神爱世人"            android:textColor="#e00"            android:textSize="70dp" />    </LinearLayout>    <RelativeLayout        android:layout_width="match_parent"        android:layout_height="0dip"        android:layout_weight="5">        <Button            android:id="@+id/button"            android:layout_width="match_parent"            android:layout_height="300dip"            android:layout_centerHorizontal="true"//在中心位置            android:layout_centerVertical="true"            android:background="#090" />        <Button            android:layout_width="40dip"            android:layout_height="40dip"            android:layout_centerInParent="true"//在上面设置的按钮的中心            android:background="#d00"            android:id="@+id/button2"            />        <Button            android:layout_width="40dip"            android:layout_height="40dip"            android:layout_centerInParent="true"            android:layout_toRightOf="@id/button2"//在按钮2的右边            android:background="#d00"            />        <Button            android:layout_width="40dip"            android:layout_height="40dip"            android:layout_centerInParent="true"            android:layout_toLeftOf="@id/button2"            android:background="#d00"            />        <Button            android:layout_width="40dip"            android:layout_height="40dip"            android:layout_centerInParent="true"            android:layout_above="@id/button2"//在按钮2 的正上方            android:background="#d00"            />        <Button            android:layout_width="40dip"            android:layout_height="40dip"            android:layout_centerInParent="true"           android:layout_below="@id/button2"//在正下方            android:background="#d00"            android:id="@+id/button3"            />        <Button            android:layout_width="40dip"            android:layout_height="40dip"            android:layout_centerInParent="true"            android:layout_below="@id/button3"            android:background="#d00"            />    </RelativeLayout>    <Button        android:layout_width="match_parent"        android:layout_height="0dip"        android:layout_weight="1"        android:text="进入第二个界面"        android:textSize="25dp"        android:textColor="#088" /></LinearLayout>

代码实现:(注意屏幕中的十字架由多个按钮排列而成,点击最下方【进入第二个界面】按钮将会进入刚才上面所显示的界面)
这里写图片描述

0 0