禁止Android不跟隨屏幕密度加載不同文件夾的資源
在AndroidManifest.xml文件中添加android:anyDensity="false"字段
高分辨率,一般我們把圖片丟這裏mipmap-hdpi
調試時默認生成的apk在:app/build/outputs/apk目錄下
Android Studio 打包時 Signature Version V1 V2
- 同時勾選V1和V2則所有機型都沒問題
- 生成目錄 E:\wamp64\www\EAider\app\release
發佈apk做代碼混淆 愛加密
match_parent和fill_parent
- fill_parent = match_parent(一般用match_parent)
- wrap_content設置一個視圖的尺寸爲wrap_content將強制性地使視圖擴展以顯示全部內容。以TextView和ImageView控件爲例,設置爲wrap_content將完整顯示其內部的文本和圖像。佈局元素將根據內容更改大小。設置一個視圖的尺寸爲wrap_content大體等同於設置Windows控件的Autosize屬性爲True。
layout_gravity和gravity
android:gravity
屬性是對該view
中內容的限定,比如一個button上面的text,你可以設置該text相對於view的靠左,靠右等位置android:layout_gravity
是用來設置該view相對與父view的位置,比如一個button在linearlayout裏,你想把該button放在linearlayout裏靠左、靠右等位置就可以通過該屬性設置android:gravity
用於設置View中內容相對於View組件的對齊方式android:layout_gravity
用於設置View組件相對於Container的對齊方式
線性佈局
- 權重用途很大
- 當
android:orientation="vertical"
時,只有水平方向的設置才起作用,垂直方向的設置不起作用。即:left,right,center_horizontal
是生效的 - 當
android:orientation="horizontal"
時,只有垂直方向的設置才起作用,水平方向的設置不起作用。即:top,bottom,center_vertical
是生效的
分隔線
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:background="#000000"/>
佈局使用RelativeLayout+LinearLayout
的weight
屬性搭配使用
相對佈局廣告彈出框Demo
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00CCCCFF">
<ImageView
android:id="@+id/img1"
android:background="#000"
android:layout_centerInParent="true"
android:layout_width="200dp"
android:layout_height="200dp" />
<ImageView
android:id="@+id/imgCancle"
android:layout_alignRight="@id/img1"
android:layout_alignTop="@id/img1"
android:background="#5555"
android:layout_marginTop="-15dp"
android:layout_marginRight="-10dp"
android:layout_width="28dp"
android:layout_height="28dp" />
</RelativeLayout>
表格佈局
幀佈局FrameLayout
android:foreground
:設置改幀佈局容器的前景圖像android:foregroundGravity
:設置前景圖像顯示的位置
網格佈局GridLayout
- 默認每個組件都是佔一行一列
- 通過
android:layout_rowSpan
與android:layout_columnSpan
設置了組件橫跨多行或者多列的話,如果你要讓組件填滿橫越過的行或列的話,需要添加android:layout_gravity = "fill"
低版本sdk如何使用GridLayout
<android.support.v7.widget.GridLayout>
,v7
包一般在sdk
下的sdk\extras\android\support\v7\gridlayout
目錄下
幾個單位
dp(dip): device independent pixels(設備獨立像素)
,不同設備有不同的顯示效果,這個和設備硬件有關,一般我們爲了支持WVGA、HVGA和QVGA推薦使用這個,不依賴像素px: pixels(像素)
,不同設備顯示效果相同,一般我們HVGA代表320x480像素,這個用的比較多pt: point
,是一個標準的長度單位,1pt=1/72英寸,用於印刷業,非常簡單易用sp: scaled pixels(放大像素)
,主要用於字體顯示best for textsize