android界面設計源碼
A. android app界面設計規范(dpi,dp,px等)
PPI(Pixels per inch):每英寸所擁有的像素數,即像素密度。
DPI(dots per inch):即每英寸上,所能印刷的網點數,一般稱為像素密度。ppi計算公式:ppi = 屏幕對角線像素數/屏幕對角線英寸數,通過勾股定理計算屏幕對角線像素數。
Screen Size(屏幕尺寸):手機屏幕尺寸大小,如3英寸、4英寸、4.3英寸、5.7英寸,指的是對角線的長度。
DIP(device independent pixel):即dip/dp,設備獨立像素。 1px = 1dp density(由dpi決定)
Resolution(解析度):指手機屏幕垂直和水平方向上的像素個數。eg解析度480 800,指該設備垂直方向有800個像素點,水平方向有480個像素點。
px(Pixel像素):相同像素的ui,在不同解析度的設備上效果不同。在小解析度設備上會放大導致失真,大解析度上被縮小。
Android Design里把主流設備的 dpi 歸成了四個檔次: 120 dpi、160 dpi、240 dpi、320 dpi ,具體見如下表格。
實際開發當中,我們經常需要對這幾個尺寸進行相互轉換(比如先在某個解析度下完成設計,然後縮放到其他尺寸微調後輸出),一般按照 dpi 之間的比例即 2:1.5:1:0.75 來給界面中的元素來進行尺寸定義。
也就是說如果以 160 dpi 作為基準的話,只要尺寸的 DP 是 4 的公倍數,XHDPI 下乘以 2,HDPI 下乘以 1.5,LDPI 下乘以 0.75 即可滿足所有尺寸下都是整數 pixel 。但假設以 240 dpi 作為標准,那需要 DP 是 3 的公倍數,XHDPI 下乘以 1.333,MDPI 下乘以 0.666 ,LDPI 下除以 2。而以 LDPI 和 XHDPI 為基準就更復雜了。同時第一款Android設備(HTC的T-Mobile G1)是屬於160dpi的。鑒於以上各種原因, 標准dpi=160
谷歌官方對dp的解釋如下:
A virtual pixel unit that you should use when defining UI layout, to express layout dimensions or position in a density-independent way.
The density-independent pixel is equivalent to one physical pixel on a 160 dpi screen, which is the baseline density assumed by the system for a "medium" density screen. At runtime, the system transparently handles any scaling of the dp units, as necessary, based on the actual density of the screen in use. The conversion of dp units to screen pixels is simple: px = dp * (dpi / 160). For example, on a 240 dpi screen, 1 dp equals 1.5 physical pixels. You should always use dp units when defining your application's UI, to ensure proper display of your UI on screens with different densities.
簡單來說,以160dpi的設備為准,該設備上1dp = 1px;如果屏幕密度大,1dip代表的px就多,比如在320dpi的屏幕上,1dip=2px(即1dp代表2個像素)。在app開發時,最好用dp來做界面的布局,以保證適配不同屏幕密度的手機。
dp和px的換算公式:
我的理解,該公式表示px的數值等於dp的數值*(設備dpi/160)
注意,px、dp是單位,但density沒單位。
applyDimension的源碼如下,可參考:
android的尺寸眾多,建議使用解析度為 720x1280 的尺寸設計。這個尺寸 720x1280中顯示完美,在 1080x1920 中看起來也比較清晰;切圖後的圖片文件大小也適中,應用的內存消耗也不會過高。
app啟動圖標為48*48dp,對應各dpi設備,圖像資源像素如下:
| mdpi | hdpi | xhdpi | xxhdpi |
| ---:| ---: | ---:| ---:| ---:|
|48 48px|72 72px|94 96px|144px 144px|
操作欄圖標為32*32dp,對應各dpi設備,圖像資源像素如下:其中圖形區域尺寸是24*24dp,可參考平時ui切圖會有部分留白。
| mdpi | hdpi | xhdpi | xxhdpi |
| ---:| ---: | ---:| ---:| ---:|
|32 32px|48 48px|64 64px|96px 96px|
通知欄圖標為24*24dp,對應各dpi設備,圖標像素如下:
| mdpi | hdpi | xhdpi | xxhdpi |
| ---:| ---: | ---:| ---:| ---:|
|24 24px|36 36px|48 48px|72px 72px|
某些場景需要用到小圖標,大小應當是16*16dp,其中圖形區域尺寸12*12dp。
| mdpi | hdpi | xhdpi | xxhdpi |
| ---:| ---: | ---:| ---:| ---:|
|16 16px|24 24px|32 32px|48px 48px|
B. 32個實用酷炫的Android開源UI框架
1.Side-Menu.Android
分類側滑菜單 , Yalantis 出品。
項目地址: https://github.com/Yalantis/Side-Menu.Android
2.Context-Menu.Android
可以方便快速集成漂亮帶有動畫效果的上下文菜單, Yalantis 出品。
項目地址: https://github.com/Yalantis/Context-Menu.Android
3.Pull-to-Refresh.Rentals-Android
提供一個簡單可以自定義的 下拉刷新 實現,Yalantis 出品。
項目地址: https://github.com/Yalantis/Pull-to-Refresh.Rentals-Android
4.Titanic
可以顯示水位上升下降的TextView
項目地址: https://github.com/RomainPiel/Titanic
5.AndroidSwipeLayout
滑動Layout ,支持單個View,ListView,GridView
項目地址: https://github.com/daimajia/AndroidSwipeLayout
Demo地址: Download Demo
6.Android Typeface Helper
可以幫你輕松實現自定義字體的庫
項目地址: https://github.com/norbsoft/android-typeface-helper
7.android-lockpattern
Android的圖案密碼解鎖
項目地址: https://code.google.com/p/android-lockpattern/
Demo地址: https://play.google.com/store/apps/details?id=group.pals.android.lib.ui.lockpattern.demo
文檔介紹: https://code.google.com/p/android-lockpattern/wiki/QuickUse
APP示例:Android開機的圖案密碼解鎖,支付寶的密碼解鎖
8.ToggleButton
狀態切換的 Button,類似 iOS,用 View 實現
項目地址: https://github.com/zcweng/ToggleButton
9.WilliamChart
繪制圖表的庫,支持LineChartView、BarChartView和StackBarChartView三中圖表類型,並且支持 Android 2.2及以上的系統。
項目地址: https://github.com/diogobernardino/WilliamChart
Demo地址: https://play.google.com/store/apps/details?id=com.db.williamchartdemo
Demo項目: https://github.com/diogobernardino/WilliamChart/tree/master/sample
10.實現滑動ViewPager漸變背景色
項目地址: https://github.com/TaurusXi/GuideBackgroundColorAnimation
11.Euclid
用戶簡歷界面, Yalantis 出品。
項目地址: https://github.com/Yalantis/Euclid
12. InstaMaterial
Instagram的一組Material 風格的概念設計
項目地址: https://github.com/frogermcs/InstaMaterial
13. SpringIndicator
使用bezier實現粘連效果的頁面指示
項目地址: https://github.com/chenupt/SpringIndicator
14. BezierDemo
仿qq消息氣泡拖拽 消失的效果。
項目地址: https://github.com/chenupt/BezierDemo
15. FoldableLayout
折疊的信紙被打開一樣的動畫效果
項目地址: https://github.com/alexvasilkov/FoldableLayout
16.Taurus
下拉刷新,Yalantis 出品。(是不是有點似曾相識呢?)
項目地址: https://github.com/Yalantis/Taurus
17. PersistentSearch
在點擊搜索的時候控制項在原有位置顯示輸入框。
項目地址: https://github.com/Quinny898/PersistentSearch
18. circular-progress-button
帶進度顯示的Button
項目地址: https://github.com/dmytrodanylyk/circular-progress-button
19. discrollview
當上下滾動的時候子元素會呈現不同動畫效果的scrollView,網頁上稱之為:視差滾動
項目地址: https://github.com/flavienlaurent/discrollview
20. sweet-alert-dialog
一個帶動畫效果的 自定義對話框樣式
項目地址: https://github.com/pedant/sweet-alert-dialog
21. android-floating-action-button
Material Desig風格的 浮動操作按鈕
項目地址: https://github.com/futuresimple/android-floating-action-button
22. android-collapse-calendar-view
可以在月視圖與周視圖之間切換的calendar控制項
項目地址: https://github.com/blazsolar/android-collapse-calendar-view
22. android-collapse-calendar-view
可以在月視圖與周視圖之間切換的calendar控制項
項目地址: https://github.com/blazsolar/android-collapse-calendar-view
23. NumberProgressBar
個簡約性感的數字進度條
項目地址: https://github.com/daimajia/NumberProgressBar
24. CircularProgressView
CircularProgressView 是通過自定義view的方式實現的Material風格的載入提示控制項,兼容任何版本。
項目地址: https://github.com/rahatarmanahmed/CircularProgressView
25. OriSim3D-Android
opengl 實現了各種折紙效果,模擬了從一張紙折疊成一條船的整個過程
項目地址: https://github.com/RemiKoutcherawy/OriSim3D-Android
26、萬能日歷控制項:CalendarView
GitHub: https://github.com/huanghaibin-dev/CalendarView
中文使用文檔: https://github.com/huanghaibin-dev/CalendarView/blob/master/QUESTION_ZH.md
27、大圖查看器: BigImage ImageView ViewPager
Github: https://github.com/SherlockGougou/BigImageViewPager
地址: https://www.jianshu.com/p/b15e65791c3f
支持超長圖、超大圖的圖片瀏覽器,優化內存,支持手勢放大、下拉關閉、查看原圖、載入百分比、保存圖片等功能。現已支持androidx。
28、安卓工具包androidUntilCode(安卓必備)
Github: https://github.com/Blankj/AndroidUtilCode/blob/master/lib/utilcode/README-CN.md
29、萬能適配器-BRAVH
官網: http://www.recyclerview.org
GitHub: https://github.com/CymChad/BaseRecyclerViewAdapterHelper
RecyclerView
作為Android最常用的控制項之一,是否常常為「她」操碎了心
BRVAH受益群體是所有Android開發者,希望更多開發者能夠一起來把這個項目做得更好幫助更多人
30、智能刷新控制項--SmartRefreshLayout
GitHub: https://github.com/scwang90/SmartRefreshLayout
中文: https://gitee.com/scwang90/SmartRefreshLayout
SmartRefreshLayout以打造一個強大,穩定,成熟的下拉刷新框架為目標,並集成各種的炫酷、多樣、實用、美觀的Header和Footer。 正如名字所說,SmartRefreshLayout是一個「聰明」或者「智能」的下拉刷新布局,由於它的「智能」,它不只是支持所有的View,還支持多層嵌套的視圖結構。 它繼承自ViewGroup 而不是FrameLayout或LinearLayout,提高了性能。 也吸取了現在流行的各種刷新布局的優點,包括谷歌官方的 SwipeRefreshLayout , 其他第三方的 Ultra-Pull-To-Refresh 、 TwinklingRefreshLayout 。 還集成了各種炫酷的 Header 和 Footer。
31、內存泄漏檢測工具--leakcanary
使用方式: https://www.jianshu.com/p/b83ddffcb3b5
LeakCanary是Square公司基於MAT開源的一個工具,用來檢測Android App中的內存泄露問題。官方地址: https://github.com/square/leakcanary
32、 1218683832 / AndroidSlidingUpPanel
SlidingUpPanelLayout:可以上下滑動的菜單布
https://github.com/1218683832/AndroidSlidingUpPanel
C. android界面設計
最下面4個按鈕用線性布局放4個button進去.
上面那些,gridview就行了.
D. 如何設計android的登錄界面
在網上在到一個登錄界面感覺挺不錯的,給大家分享一下~先看效果圖:
這個Demo除了按鈕、小貓和Logo是圖片素材之外,其餘的UI都是通過代碼實現的。
?
一、背景
背景藍色漸變,是通過一個xml文件來設置的。代碼如下:
background_login.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:andro>
<gradient
android:startColor="#FFACDAE5"
android:endColor="#FF72CAE1"
android:angle="45"
/>
</shape>
startColor是漸變開始的顏色值,endColor是漸變結束的顏色值,angle是漸變的角度。其中#FFACDAE5中,FF是Alpha值,AC是RGB的R值,DA是RGB的G值,E5是RGB的B值,每個值在00~FF取值,即透明度、紅、綠、藍有0~255的分值,像要設置具體的顏色,可以在PS上的取色器上查看設置。
?
?
二、圓角白框
效果圖上面的並不是白框,其實框是白色的,只是設置了透明值,也是靠一個xml文件實現的。
background_login_div.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:andro>
<solid android:color="#55FFFFFF" />
<!-- 設置圓角
注意: bottomRightRadius是左下角而不是右下角 bottomLeftRadius右下角-->
<corners android:topLeftRadius="10dp" android:topRightRadius="10dp"
android:bottomRightRadius="10dp" android:bottomLeftRadius="10dp"/>
</shape>
?
三、界面的布局
界面的布局挺簡單的,就直接貼代碼啦~
login.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:andro
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background_login">
<!-- padding 內邊距 layout_margin 外邊距
android:layout_alignParentTop 布局的位置是否處於頂部 -->
<RelativeLayout
android:
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="15dip"
android:layout_margin="15dip"
android:background="@drawable/background_login_div_bg" >
<!-- 賬號 -->
<TextView
android:
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="5dp"
android:text="@string/login_label_username"
/>
<EditText
android:
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/login_username_hint"
android:layout_below="@id/login_user_input"
android:singleLine="true"
android:inputType="text"/>
<!-- 密碼 text -->
<TextView
android:
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/username_edit"
android:layout_marginTop="3dp"
android:text="@string/login_label_password"
/>
<EditText
android:
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/login_password_input"
android:password="true"
android:singleLine="true"
android:inputType="textPassword" />
<!-- 登錄button -->
<Button
android:
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/password_edit"
android:layout_alignRight="@id/password_edit"
android:text="@string/login_label_signin"
android:background="@drawable/blue_button" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView android:
android:text="@string/login_register_link"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:textColor="#888"
android:textColorLink="#FF0066CC" />
<ImageView android:
android:src="@drawable/cat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginRight="25dp"
android:layout_marginLeft="10dp"
android:layout_marginBottom="25dp" />
<ImageView android:src="@drawable/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/miniTwitter_logo"
android:layout_alignBottom="@id/miniTwitter_logo"
android:paddingBottom="8dp"/>
</RelativeLayout>
</LinearLayout>
E. android手機購物車的界面如何設計求源代碼
android手機購物車的界面如何設
肯定比較多,了解分析
大
F. 用Android編寫,求像推箱子那種一格一格的界面設計的源代碼,先謝謝了!!求發郵箱[email protected]
你這邊是 老師安排的作業還是 畢業方面的作業
G. 安卓開發界面設計button無法放到界面底端
換將LinearLayout換成RelativeLayout,採用相對布局使用 android:layout_alignParentBottom="true"就可以把你想要的組建放大父類布局的底端了
H. android 應用界面設計問題,急啊
這個在layout.xml文件里就可以搞定吧?不行就用Java代碼動態實現。