Android基础第一天易忘部分

1.gravity:控制当前控件内容显示区域

<Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="right"
        android:text="按钮1" />


2.layout_gravity:当前控件在父元素的位置   这个属性可以用在LinerLayoutFrameLayout,和它效果一样的是RelativeLayout的alignParentTop|Bottom|Left|Right。

<Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:text="按钮2" />

3.layout_alignBaseline:与指定控件在同一直线上,也就是中心点对齐。

4.常见的密度比值:   px除以dp的值

240*320的密度比值是:0.75

320*480的密度比值是:1.0

480*800的密度比值是:1.5


5.冒烟测试(瞎按)

adb shell monkey -p 包名 -v 1000

用来测试app程序的,v后面是指操作的次数


6.安卓权限




7.Xml解析的时候需要注意的是

获取标签里的内容的时候用的是parser.nextText()而不是parser.getText()


8.SharedPreference创建的xml只需要指定文件名,不需要后缀名。

而XmlSerializer和XmlPullParser创建的xml需要指定后缀名。


1.TableLayout的TableRow的宽度就算设置了也是match_parent

2.Android 4.0之前读SD卡是不需要权限的,但是4.0之后可以在手机上开发者选项设置SD卡读写保护,这时再读SD卡必须要读SD卡的权限(模拟器可能不支持,真机没问题)

3.如果希望按比重来分配组件占用宽度或高度的话,可以在容器中先设定容器的比重和。android:weightSum=“2”,如果不设定那么系统就会查找容器中每个组件的android:layout_weight属性,加起来后就是android:weightSum。

4.下图的用android:layout_weight画


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <Button 
        android:layout_width="wrap_content"
    	android:layout_height="wrap_content"
    	android:text="上面"/>
    <!-- 中间的Button设置layout_weight属性后就会填充中间部分 -->
    <Button 
        android:layout_weight="1"
        android:layout_width="wrap_content"
    	android:layout_height="wrap_content"
    	android:text="中间"/>
    <Button 
        android:layout_width="wrap_content"
    	android:layout_height="wrap_content"
    	android:text="底下"/>
</LinearLayout>


5.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <Button
        android:id="@+id/zj"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="正中间" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:text="左边" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:text="右边" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:text="上边" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:text="下边" />

    <Button 
        android:layout_alignTop="@id/zj"
        android:layout_toLeftOf="@id/zj"
        android:layout_width="wrap_content"
    	android:layout_height="wrap_content"
    	android:text="左"/>
    
    <Button 
        android:layout_above="@+id/zj"
        android:layout_width="wrap_content"
        android:layout_centerHorizontal="true"
    	android:layout_height="wrap_content"
    	android:text="上"/>
    
    <!-- 
    	layout_alignBaseline与指定组件的中心线对齐
     -->
    <Button 
        android:layout_alignBaseline="@id/zj"
        android:layout_toRightOf="@id/zj"
        android:layout_width="wrap_content"
    	android:layout_height="wrap_content"
    	android:text="右"/>
    
    <Button 
        android:layout_below="@id/zj"
        android:layout_centerHorizontal="true"
        android:layout_width="wrap_content"
    	android:layout_height="wrap_content"
    	android:text="下"/>
</RelativeLayout>


6.Android路径

getApplicationContext().getFilesDir();    /data/data/包名/files/  系统自带的清除数据功能是会将这个应用文件夹下的内容清空(清空该包下除lib外所有的包,这样可能导致程序运行错误或者数据错误)
getApplicationContext().getCacheDir();  /data/data/包名/cache/      清理缓存的软件清理的是这个文件夹下的内容,所以这里尽量存无关紧要的缓存文件

FileOutputStream fos = openFileOutput("haha.txt", Context.MODE_WORLD_READABLE);    打开一个叫haha.txt文件的输出流   /data/data/包名/files/haha.txt    第一个参数被打开的文件   第二个参数文件的权限  可读、可写

File sdCardFile = Environment.getExternalStorageDirectory();   /mnt/sdcard/获取手机SD卡路径


7.Android的API提供的睡眠方法SystemClock.sleep(1000);

SystemClock.sleep(1000);//这个方法是android的API提供的睡眠,和下面的区别是不需要抓取异常
try {
	Thread.sleep(1000);
} catch (InterruptedException e) {
	e.printStackTrace();
}



评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值