Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲

Android 手把手打造精美的用戶登入介面

編輯:關於 Android 程式設計

這篇要帶大家一步一步打造一個類似下圖那樣的登入 UI 介面:


一、準備圖片資源

先把需要用到的圖示(如 Facebook、LinkedIn 的連線按鈕)放進 drawable 資料夾裡,並在 strings.xml 中把要顯示的文字整理好。

二、ImageButton 設定

版面配置程式碼如下:

  

幾個關鍵屬性說明:

・第一個 ImageButton 透過 android:layout_alignParentTop="true",達到與父容器頂端對齊;透過 android:layout_centerHorizontal="true",達到水平居中。

・第二個 ImageButton 則透過 android:layout_alignLeft="@id/btnFacebook",達到與第一顆按鈕左緣對齊。

目前的畫面效果如下:


三、TextView 設定

拖五個 TextView 到版面中,並把要顯示的文字抽到 res/values/strings.xml 裡管理,讓介面更容易維護:

  LoginLayout Facebook LinkedIn To use Highlight, please sign in with one of the services below: Why not email? Highlight is based on real identity and mutual friends. Using these services allows us to show you how you are connected to the people around you. It also makes it super easy to create a Highlight profile.    We will not post things without your permission. 

接著為各 TextView 掛上對應的文字並做基本屬性設定,完整的版面配置如下:

          

做完這些設定後,畫面效果如下:


四、為「let us know」加上超連結

最後我們用 Html.fromHtml 讓 TextView 中的文字支援點擊連結:

public class MainActivity extends Activity { TextView mTVFeedBack; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mTVFeedBack = (TextView)findViewById(R.id.textView4); mTVFeedBack.setText(Html.fromHtml(getString(R.string.feedback_label))); } }

最終的 UI 成果如下圖所示:


五、Demo 下載:

完整 Demo 可從以下地址下載:https://download.csdn.net/detail/kongre/7299753

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © Android教程網 All Rights Reserved