安卓第三次作业
package com.example.aaa;
import android.support.v7.app.ActionBarActivity;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends ActionBarActivity implements View.OnClickListener{
EditText username;
EditText password;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
username = (EditText)findViewById(R.id.username);
password = (EditText)findViewById(R.id.password);
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.qq.MainActivity" >
<TextView
android:id="@+id/tv_account"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:background="#FFFFFF"
android:text="帐号:"
android:textSize="30dp"
/>
<TextView
android:id="@+id/tv_account1"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_below="@+id/tv_account"
android:layout_centerVertical="true"
android:background="#FFFFFF"
android:text="密码:"
android:textSize="30dp"
/>
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/tv_account1"
android:layout_alignRight="@+id/tv_account1"
android:layout_below="@+id/tv_account1"
android:background="#545bcb"
android:textColor="#ffffff"
android:textSize="20dp"
android:text="登录"
android:onClick="CCC"/>
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_above="@+id/tv_account"
android:src="@drawable/logo" />
<EditText
android:id="@+id/username"
android:layout_width="400dp"
android:layout_height="40dp"
android:layout_below="@+id/tv_account"
android:ems="10"
android:gravity="center"
android:background="@null"
/>
<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_centerInParent="true"
android:ems="10"
android:gravity="center"
android:background="@null"
/>
</RelativeLayout>![](https://img2018.cnblogs.com/blog/1803511/201909/1803511-20190914112744151-517910276.png)
import android.support.v7.app.ActionBarActivity;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends ActionBarActivity implements View.OnClickListener{
EditText username;
EditText password;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
username = (EditText)findViewById(R.id.username);
password = (EditText)findViewById(R.id.password);
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.qq.MainActivity" >
<TextView
android:id="@+id/tv_account"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:background="#FFFFFF"
android:text="帐号:"
android:textSize="30dp"
/>
<TextView
android:id="@+id/tv_account1"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_below="@+id/tv_account"
android:layout_centerVertical="true"
android:background="#FFFFFF"
android:text="密码:"
android:textSize="30dp"
/>
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/tv_account1"
android:layout_alignRight="@+id/tv_account1"
android:layout_below="@+id/tv_account1"
android:background="#545bcb"
android:textColor="#ffffff"
android:textSize="20dp"
android:text="登录"
android:onClick="CCC"/>
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_above="@+id/tv_account"
android:src="@drawable/logo" />
<EditText
android:id="@+id/username"
android:layout_width="400dp"
android:layout_height="40dp"
android:layout_below="@+id/tv_account"
android:ems="10"
android:gravity="center"
android:background="@null"
/>
<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_centerInParent="true"
android:ems="10"
android:gravity="center"
android:background="@null"
/>
</RelativeLayout>
![](https://img2018.cnblogs.com/blog/1803511/201909/1803511-20190914112744151-517910276.png)