android一個登陸介面的設計
阿新 • • 發佈:2019-02-13
說起登陸介面的設計,大家可能都會說這個挺簡單的的啊,弄個佈局,加幾個控制元件一個登陸介面就出來了,但我今天想說一下自己在設計一個登陸介面時遇到的問題,而我這個登陸介面的設計重點就是在一個水平佈局上放了一個checkbox和一個登陸的button,在checkbox放上之後,之後的那個button在這個水平佈局的空餘空間上居中,這個對於高手來說可能不是什麼問題了,而讓我奇怪的是當我的佈局屬性設定為水平時,我的登陸button並不能居中,而只有在垂直的屬性下button才能居中。
所以現在把這個程式碼貼出來,介面的效果並沒有做什麼美化,只是一些系統控制元件的組合。
選看一下效果圖:
所以這個設計的重點也就是在紅色區域裡讓button居中。
下面是改佈局的xml檔案
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="賬號:"/> <EditText android:layout_width="240dip" android:layout_height="wrap_content" android:text="mumayi" android:id="@+id/edtuser"/> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="密碼:"/> <EditText android:layout_width="240dip" android:layout_height="wrap_content" android:password="true" android:id="@+id/edtpsd"/> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" > <LinearLayout android:layout_width="wrap_content" android:layout_height="fill_parent" android:orientation="vertical" > <CheckBox android:id="@+id/checkbox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="記住密碼" /> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <Button android:id="@+id/login" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:text="登入" /> </LinearLayout> </LinearLayout> </LinearLayout>