Android仿QQ登陸窗口實現(xiàn)原理
今天根據(jù)騰訊qq,我們做一個練習(xí),來學(xué)習(xí)如何制作一個漂亮的布局。首先看一下官方圖片

還是一個啟動畫面,之后進入登錄頁面,導(dǎo)航頁面就不介紹了,大家可以參考微信的導(dǎo)航頁面。首先程序進入SplashActivity,就是啟動頁面,Activity代碼如下:
package com.example.imitateqq;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
public class SplashActivity extends Activity {
private Intent intent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
startMainAvtivity();
}
private void startMainAvtivity() {
new Handler().postDelayed(new Runnable() {
public void run() {
intent=new Intent(SplashActivity.this,QQ.class);
startActivity(intent);
SplashActivity.this.finish();//結(jié)束本Activity
}
}, 1000);//設(shè)置執(zhí)行時間
}
}
xml布局文件就是一個全屏的圖片,要注意的是設(shè)置android:scaleType ="matrix"這個屬性。不然不會全屏
<? 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" >
< ImageView
android:layout_width ="match_parent"
android:layout_height ="match_parent"
android:scaleType ="matrix"
android:src ="@drawable/splash" />
</ LinearLayout>
過1秒之后轉(zhuǎn)入登陸頁面,從圖片我們可以看出,騰訊的UI做的還是相當(dāng)美觀漂亮的,既簡潔又不失美觀。先分析一下這個登錄界面,從整體可以看出,根布局的背景色是藍色的,而那個QQ 2012 Android其實是一個圖片背景色和根布局的背景色一樣,這樣就不會有視覺偏差。下面就是兩個文本框EditText了,注意這里和官方給的不一樣,因為后面有一個小箭頭,當(dāng)點擊這個箭頭時,會在第一個文本框的下面顯示已經(jīng)輸入的qq號碼,在qq號碼的后面還有刪除qq信息的按鈕。這個地方需要注意一下。再往下就是登陸B(tài)utton以及那連個“記住密碼”和“注冊新賬號”比較簡單,注意位置的安排即可。最后就是最下面的“更多登陸選項”,當(dāng)點擊的時候會向上彈出一些內(nèi)容,其實就是一個隱藏的布局,當(dāng)點擊上面的時候,使下面隱藏的布局顯示。當(dāng)然也可以使用滑動抽屜來做,但是相對來說比較麻煩。下面看一下xml代碼,相信大家就會一路了然。
< RelativeLayout xmlns:android ="http://schemas.android.com/apk/res/android"
xmlns:tools= "http://schemas.android.com/tools"
android:layout_width= "match_parent"
android:layout_height= "match_parent"
android:background= "@drawable/login_bg" >
< ImageView
android:id ="@+id/loginbutton"
android:layout_width ="wrap_content"
android:layout_height ="wrap_content"
android:layout_centerHorizontal ="true"
android:layout_marginTop ="50dp"
android:src ="@drawable/login_pic" />
<LinearLayout
android:id ="@+id/input"
android:layout_width ="fill_parent"
android:layout_height ="wrap_content"
android:layout_below ="@id/loginbutton"
android:layout_marginLeft ="28.0dip"
android:layout_marginRight ="28.0dip"
android:background ="@drawable/login_input"
android:orientation ="vertical" >
< LinearLayout
android:layout_width ="fill_parent"
android:layout_height ="44.0dip"
android:background ="@drawable/login_input"
android:gravity ="center_vertical"
android:orientation ="horizontal" >
< EditText
android:id ="@+id/searchEditText"
android:layout_width ="0dp"
android:layout_height ="fill_parent"
android:layout_weight ="1"
android:background ="@null"
android:ems ="10"
android:imeOptions ="actionDone"
android:singleLine ="true"
android:textSize ="16sp" >
< requestFocus />
</ EditText>
< Button
android:id ="@+id/button_clear"
android:layout_width ="20dip"
android:layout_height ="20dip"
android:layout_marginRight ="8dip"
android:background ="@drawable/login_input_arrow"
android:visibility ="visible" />
</ LinearLayout>
< View
android:layout_width ="fill_parent"
android:layout_height ="1.0px"
android:layout_marginLeft ="1.0px"
android:layout_marginRight ="1.0px"
android:background ="#ffc0c3c4" />
< EditText
android:id ="@+id/password"
android:layout_width ="fill_parent"
android:layout_height ="44.0dip"
android:background ="#00ffffff"
android:gravity ="center_vertical"
android:inputType ="textPassword"
android:maxLength ="16"
android:maxLines ="1"
android:textColor ="#ff1d1d1d"
android:textColorHint ="#ff666666"
android:textSize ="16.0sp" />
</LinearLayout >
<Button
android:id ="@+id/buton1"
android:layout_width ="270dp"
android:background ="@drawable/chat_send_button_bg"
android:paddingTop ="5.0dip"
android:layout_height ="50dp"
android:layout_marginLeft ="28.0dip"
android:layout_marginRight ="28.0dip"
android:layout_marginTop ="12.0dip"
android:layout_below ="@+id/input"
android:gravity ="center"
android:textSize ="20dp"
android:text = "登錄" />
<RelativeLayout
android:id ="@+id/relative"
android:layout_width ="fill_parent"
android:layout_height ="wrap_content"
android:layout_alignLeft ="@+id/input"
android:layout_alignRight ="@+id/input"
android:layout_below ="@id/buton1" >
< CheckBox
android:id ="@+id/auto_save_password"
android:layout_width ="wrap_content"
android:layout_height ="wrap_content"
android:layout_alignParentLeft ="true"
android:background ="@null"
android:button ="@null"
android:checked ="true"
android:drawableLeft ="@drawable/checkbox_bg1"
android:drawablePadding ="4.0dip"
android:text = "記住密碼"
android:textColor ="#ffffffff"
android:textSize ="12.0sp" />
< Button
android:id ="@+id/regist"
android:layout_width ="wrap_content"
android:layout_height ="wrap_content"
android:layout_alignParentRight ="true"
android:background ="@drawable/login_reg_normal"
android:clickable ="true"
android:gravity ="left|center"
android:paddingLeft ="8.0dip"
android:paddingRight ="18.0dip"
android:text = "注冊新賬號"
android:textColor ="#ffffffff"
android:textSize ="12.0sp" />
</RelativeLayout >
<LinearLayout
android:id ="@+id/more_bottom"
android:layout_width ="fill_parent"
android:layout_height ="wrap_content"
android:layout_alignParentBottom ="true"
android:background ="@drawable/login_moremenu_back"
android:orientation ="vertical" >
<RelativeLayout
android:id ="@+id/input2"
android:layout_width ="fill_parent"
android:layout_height ="40dp"
android:background ="@drawable/login_moremenu_back"
android:orientation ="vertical" >
< ImageView
android:id ="@+id/more_image"
android:layout_width ="wrap_content"
android:layout_height ="wrap_content"
android:layout_centerVertical ="true"
android:layout_marginRight ="5.0dip"
android:layout_toLeftOf ="@+id/more_text"
android:clickable ="false"
android:src ="@drawable/login_more_up" />
< TextView
android:id ="@+id/more_text"
android:layout_width ="wrap_content"
android:layout_height ="wrap_content"
android:layout_centerInParent ="true"
android:background ="@null"
android:gravity ="center"
android:maxLines ="1"
android:text = "更多登陸選項"
android:textColor ="#ffc6e6f9"
android:textSize ="14.0sp" />
</RelativeLayout >
<LinearLayout
android:id ="@+id/morehidebottom"
android:layout_width ="fill_parent"
android:layout_height ="wrap_content"
android:orientation ="vertical"
android:visibility ="gone" >
< View
android:layout_width ="fill_parent"
android:layout_height ="1.0px"
android:background ="#ff005484" />
< View
android:layout_width ="fill_parent"
android:layout_height ="1.0px"
android:background ="#ff0883cb" />
< LinearLayout
android:layout_width ="fill_parent"
android:layout_height ="wrap_content"
android:layout_marginLeft ="30.0dip"
android:layout_marginRight ="30.0dip"
android:layout_marginTop ="12.0dip"
android:orientation ="horizontal" >
< CheckBox
android:id ="@+id/hide_login"
android:layout_width ="1.0px"
android:layout_height ="wrap_content"
android:layout_weight ="2.0"
android:background ="@null"
android:button ="@null"
android:checked ="false"
android:drawableLeft ="@drawable/checkbox_bg1"
android:drawablePadding ="4.0dip"
android:text = "隱身登陸"
android:textColor ="#ffc6e6f9"
android:textSize ="12.0sp" />
< CheckBox
android:id ="@+id/silence_login"
android:layout_width ="1.0px"
android:layout_height ="wrap_content"
android:layout_weight ="1.0"
android:background ="@null"
android:button ="@null"
android:checked ="false"
android:drawableLeft ="@drawable/checkbox_bg1"
android:drawablePadding ="4.0dip"
android:text = "靜音登錄"
android:textColor ="#ffc6e6f9"
android:textSize ="12.0sp" />
</ LinearLayout>
< LinearLayout
android:layout_width ="fill_parent"
android:layout_height ="wrap_content"
android:layout_marginBottom ="18.0dip"
android:layout_marginLeft ="30.0dip"
android:layout_marginRight ="30.0dip"
android:layout_marginTop ="18.0dip"
android:orientation ="horizontal" >
< CheckBox
android:id ="@+id/accept_accounts"
android:layout_width ="1.0px"
android:layout_height ="wrap_content"
android:layout_weight ="2.0"
android:background ="@null"
android:button ="@null"
android:checked ="true"
android:drawableLeft ="@drawable/checkbox_bg1"
android:drawablePadding ="4.0dip"
android:singleLine ="true"
android:text = "允許手機/電腦同時在心線"
android:textColor ="#ffc6e6f9"
android:textSize ="12.0sp" />
< CheckBox
android:id ="@+id/accept_troopmsg"
android:layout_width ="1.0px"
android:layout_height ="wrap_content"
android:layout_weight ="1.0"
android:background ="@null"
android:button ="@null"
android:checked ="true"
android:drawableLeft ="@drawable/checkbox_bg1"
android:drawablePadding ="4.0dip"
android:text = "接受群消息"
android:textColor ="#ffc6e6f9"
android:textSize ="12.0sp" />
</ LinearLayout>
</ LinearLayout>
</LinearLayout >
</ RelativeLayout>
各個組件的使用沒有問題,關(guān)鍵是如何設(shè)置他們的屬性,來獲得一個比較美觀的效果,大家可以參考這個例子,來做一下練習(xí),來強化UI的設(shè)計。從這個例子中就可以學(xué)到很多東西,比如ViwGroup的使用(如何槍套),background的設(shè)置,例如同時使用兩個Edittext,設(shè)置android:background ="@null"設(shè)置為空的時候就不會產(chǎn)生間隔了。這個要自己多做設(shè)計,時間長了就會有感悟了。最后看一下MainActivity的代碼,布局簡單
package com.example.imitateqq;
import android.os.Bundle;
import android.app.Activity;
import android.app.Dialog;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
public class QQ extends Activity implements OnClickListener{
private Button login_Button;
private View moreHideBottomView,input2;
private ImageView more_imageView;
private boolean mShowBottom = false;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_qq);
initView();
}
private void initView() {
login_Button=(Button) findViewById(R.id.buton1);
login_Button.setOnClickListener(this);
moreHideBottomView=findViewById(R.id.morehidebottom);
more_imageView=(ImageView) findViewById(R.id.more_image);
input2=findViewById(R.id.input2);
input2.setOnClickListener( this);
}
public void showBottom(boolean bShow){
if(bShow){
moreHideBottomView.setVisibility(View.GONE);
more_imageView.setImageResource(R.drawable.login_more_up);
mShowBottom = true;
}else{
moreHideBottomView.setVisibility(View.VISIBLE);
more_imageView.setImageResource(R.drawable.login_more);
mShowBottom = false;
}
}
public void onClick(View v) {
switch(v.getId())
{
case R.id.input2:
showBottom(!mShowBottom);
break;
case R.id.buton1:
showRequestDialog();
break;
default:
break;
}
}
private Dialog mDialog = null;
private void showRequestDialog()
{
if (mDialog != null)
{
mDialog.dismiss();
mDialog = null;
}
mDialog = DialogFactory.creatRequestDialog(this, "正在驗證賬號...");
mDialog.show();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_qq, menu);
return true;
}
}
最后效果如下:


總結(jié):本文可以作為一個UI練習(xí)Demo,大家可以自己獨立去寫,有問題的可以留下郵箱我給你發(fā)一下源碼作為參考。下一篇將寫主頁面的實現(xiàn),歡迎大家關(guān)注。
- Android仿QQ空間底部菜單示例代碼
- Android仿QQ空間主頁面的實現(xiàn)
- Android ScrollView滑動實現(xiàn)仿QQ空間標(biāo)題欄漸變
- Android仿QQ好友列表分組實現(xiàn)增刪改及持久化
- Android仿QQ滑動彈出菜單標(biāo)記已讀、未讀消息
- Android仿QQ聊天撒花特效 很真實
- Android應(yīng)用中拍照后獲取照片路徑并上傳的實例分享
- android文件上傳示例分享(android圖片上傳)
- Android實現(xiàn)本地上傳圖片并設(shè)置為圓形頭像
- Android使用post方式上傳圖片到服務(wù)器的方法
- android上傳圖片到PHP的過程詳解
- Android中自定義PopupWindow實現(xiàn)彈出框并帶有動畫效果
- Android編程實現(xiàn)仿QQ發(fā)表說說,上傳照片及彈出框效果【附demo源碼下載】
相關(guān)文章
Android音頻開發(fā)之音頻采集的實現(xiàn)示例
本篇文章主要介紹了Android音頻開發(fā)之音頻采集的實現(xiàn)示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-04-04
Android 中圖片和按鈕按下狀態(tài)變化實例代碼解析
這篇文章通過實例代碼給大家總結(jié)了android 中圖片和按鈕按下狀態(tài)變化問題,本文通過實例代碼給大家介紹的非常詳細,感興趣的朋友跟隨腳本之家小編一起學(xué)習(xí)吧2018-06-06
android studio 打包自動生成版本號與日期,apk輸入路徑詳解
這篇文章主要介紹了android studio 打包自動生成版本號與日期,apk輸入路徑詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-03-03
Android 開發(fā)手機(三星)拍照應(yīng)用照片旋轉(zhuǎn)問題解決辦法
這篇文章主要介紹了Android 開發(fā)手機(三星)拍照應(yīng)用照片旋轉(zhuǎn)問題解決辦法的相關(guān)資料,需要的朋友可以參考下2017-04-04
Android基于TextView實現(xiàn)的跑馬燈效果實例
這篇文章主要介紹了Android基于TextView實現(xiàn)的跑馬燈效果,以完整實例形式分析了Android使用TextView通過屬性設(shè)置及功能代碼實現(xiàn)跑馬燈效果的相關(guān)技巧,需要的朋友可以參考下2016-02-02

