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


還是一個(gè)啟動(dòng)畫(huà)面,之后進(jìn)入登錄頁(yè)面,導(dǎo)航頁(yè)面就不介紹了,大家可以參考微信的導(dǎo)航頁(yè)面。首先程序進(jìn)入SplashActivity,就是啟動(dòng)頁(yè)面,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í)行時(shí)間
}
}
xml布局文件就是一個(gè)全屏的圖片,要注意的是設(shè)置android:scaleType ="matrix"這個(gè)屬性。不然不會(huì)全屏
<? 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>
過(guò)1秒之后轉(zhuǎn)入登陸頁(yè)面,從圖片我們可以看出,騰訊的UI做的還是相當(dāng)美觀漂亮的,既簡(jiǎn)潔又不失美觀。先分析一下這個(gè)登錄界面,從整體可以看出,根布局的背景色是藍(lán)色的,而那個(gè)QQ 2012 Android其實(shí)是一個(gè)圖片背景色和根布局的背景色一樣,這樣就不會(huì)有視覺(jué)偏差。下面就是兩個(gè)文本框EditText了,注意這里和官方給的不一樣,因?yàn)楹竺嬗幸粋€(gè)小箭頭,當(dāng)點(diǎn)擊這個(gè)箭頭時(shí),會(huì)在第一個(gè)文本框的下面顯示已經(jīng)輸入的qq號(hào)碼,在qq號(hào)碼的后面還有刪除qq信息的按鈕。這個(gè)地方需要注意一下。再往下就是登陸B(tài)utton以及那連個(gè)“記住密碼”和“注冊(cè)新賬號(hào)”比較簡(jiǎn)單,注意位置的安排即可。最后就是最下面的“更多登陸選項(xiàng)”,當(dāng)點(diǎn)擊的時(shí)候會(huì)向上彈出一些內(nèi)容,其實(shí)就是一個(gè)隱藏的布局,當(dāng)點(diǎn)擊上面的時(shí)候,使下面隱藏的布局顯示。當(dāng)然也可以使用滑動(dòng)抽屜來(lái)做,但是相對(duì)來(lái)說(shuō)比較麻煩。下面看一下xml代碼,相信大家就會(huì)一路了然。
< 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 = "注冊(cè)新賬號(hào)"
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 = "更多登陸選項(xiàng)"
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 = "允許手機(jī)/電腦同時(shí)在心線"
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>
各個(gè)組件的使用沒(méi)有問(wèn)題,關(guān)鍵是如何設(shè)置他們的屬性,來(lái)獲得一個(gè)比較美觀的效果,大家可以參考這個(gè)例子,來(lái)做一下練習(xí),來(lái)強(qiáng)化UI的設(shè)計(jì)。從這個(gè)例子中就可以學(xué)到很多東西,比如ViwGroup的使用(如何槍套),background的設(shè)置,例如同時(shí)使用兩個(gè)Edittext,設(shè)置android:background ="@null"設(shè)置為空的時(shí)候就不會(huì)產(chǎn)生間隔了。這個(gè)要自己多做設(shè)計(jì),時(shí)間長(zhǎng)了就會(huì)有感悟了。最后看一下MainActivity的代碼,布局簡(jiǎn)單
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, "正在驗(yàn)證賬號(hào)...");
mDialog.show();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_qq, menu);
return true;
}
}
最后效果如下:
總結(jié):本文可以作為一個(gè)UI練習(xí)Demo,大家可以自己獨(dú)立去寫(xiě),有問(wèn)題的可以留下郵箱我給你發(fā)一下源碼作為參考。下一篇將寫(xiě)主頁(yè)面的實(shí)現(xiàn),歡迎大家關(guān)注。
- Android仿QQ空間底部菜單示例代碼
- Android仿QQ空間主頁(yè)面的實(shí)現(xiàn)
- Android ScrollView滑動(dòng)實(shí)現(xiàn)仿QQ空間標(biāo)題欄漸變
- Android仿QQ好友列表分組實(shí)現(xiàn)增刪改及持久化
- Android仿QQ滑動(dòng)彈出菜單標(biāo)記已讀、未讀消息
- Android仿QQ聊天撒花特效 很真實(shí)
- Android應(yīng)用中拍照后獲取照片路徑并上傳的實(shí)例分享
- android文件上傳示例分享(android圖片上傳)
- Android實(shí)現(xiàn)本地上傳圖片并設(shè)置為圓形頭像
- Android使用post方式上傳圖片到服務(wù)器的方法
- android上傳圖片到PHP的過(guò)程詳解
- Android中自定義PopupWindow實(shí)現(xiàn)彈出框并帶有動(dòng)畫(huà)效果
- Android編程實(shí)現(xiàn)仿QQ發(fā)表說(shuō)說(shuō),上傳照片及彈出框效果【附demo源碼下載】
相關(guān)文章
Android獲取手機(jī)的版本號(hào)等信息的代碼
這篇文章主要為大家詳細(xì)介紹了Android獲取手機(jī)的版本號(hào)等信息的代碼,代碼很精彩,感興趣的小伙伴們可以參考一下2016-07-07flutter PositionedTransition實(shí)現(xiàn)縮放動(dòng)畫(huà)
這篇文章主要為大家詳細(xì)介紹了flutter PositionedTransition實(shí)現(xiàn)縮放動(dòng)畫(huà),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-07-07淺談Android IPC機(jī)制之Binder的工作機(jī)制
IPC機(jī)制即為跨進(jìn)程通信,是inter-Process Communication的縮寫(xiě)。是指兩個(gè)進(jìn)程之間進(jìn)行通信。在說(shuō)進(jìn)程通信之前,我們的弄明白什么是線程,什么是進(jìn)程。進(jìn)程和線程是兩個(gè)截然不同的概念。本文將介紹Android IPC機(jī)制之Binder的工作機(jī)制。2021-06-06Android JNI c/c++調(diào)用java的實(shí)例
這篇文章主要介紹了Android JNI c/c++調(diào)用java的實(shí)例的相關(guān)資料,需要的朋友可以參考下2017-07-07Android編程之SMS讀取短信并保存到SQLite的方法
這篇文章主要介紹了Android編程之SMS讀取短信并保存到SQLite的方法,涉及Android針對(duì)SMS短信及SQLite數(shù)據(jù)庫(kù)的相關(guān)操作技巧,需要的朋友可以參考下2015-11-11Android實(shí)現(xiàn)自定義ImageView的圓角矩形圖片效果
android顯示圓角矩形的圖片其原理就是首先獲取到圖片的Bitmap,然后進(jìn)行裁剪對(duì)應(yīng)的圓角矩形的bitmap,然后在onDraw()進(jìn)行繪制圓角矩形圖片輸出2018-05-05Android React Native原生模塊與JS模塊通信的方法總結(jié)
這篇文章主要介紹了Android React Native原生模塊與JS模塊通信的方法總結(jié)的相關(guān)資料,需要的朋友可以參考下2017-02-02flutter傳遞值到任意widget(當(dāng)需要widget嵌套使用需要傳遞值的時(shí)候)
這篇文章主要介紹了flutter傳遞值到任意widget(當(dāng)需要widget嵌套使用需要傳遞值的時(shí)候),本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-07-07ubuntu 12.10 上 android 編譯環(huán)境搭建的深入解析
本篇文章是對(duì)ubuntu 12.10上android 編譯環(huán)境的搭建進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06android電源信息查看(電量、溫度、電壓)實(shí)例代碼
這篇文章主要介紹了android電源信息查看方法,以實(shí)例形式較為詳細(xì)的分析了Android實(shí)現(xiàn)電源電量、電壓、溫度等信息查看的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-10-10