[android]登陆页面

it2022-05-09  33

关于如何创建一个项目,可以点击此处


代码部分

在新建完一个项目之后,依次点击: res -->> layout -->> activity_1.xml 将下面的代码复制到 .xml文件中。

效果图

<?xml version="1.0" encoding="utf-8"?> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/bg3" android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android"> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" > <ImageView android:id="@+id/imageView1" android:layout_width="320dp" android:layout_height="80dp" android:layout_marginTop="40dp" android:src="@drawable/bg1" /> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="20dp"> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Õ˺Å" android:textSize="20sp" android:textColor="@color/black" android:layout_marginLeft="60dp" /> <EditText android:id="@+id/editText1" android:layout_width="200dp" android:layout_height="wrap_content" android:ems="10" android:hint="ÇëÊäÈëÕ˺Å" /> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" > <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@color/black" android:text="ÃÜÂë" android:textSize="20sp" android:layout_marginLeft="60dp" /> <EditText android:id="@+id/editText2" android:layout_width="200dp" android:layout_height="wrap_content" android:ems="10" android:hint="ÇëÊäÈëÃÜÂë" /> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:layout_gravity="center" > <Button android:id="@+id/denglu" android:layout_width="250dp" android:layout_height="25dp" android:layout_marginLeft="5dp" android:layout_marginTop="15dp" android:background="@color/red" android:text="µÇ½" android:textColor="@color/white" /> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" > <Button android:id="@+id/zhuce" android:layout_width="250dp" android:layout_height="25dp" android:layout_marginLeft="5dp" android:layout_marginTop="15dp" android:background="#c0c0c0" android:text="×¢²á" android:textColor="@color/white" /> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:orientation="horizontal"> <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@color/black" android:text="ÊÇ·ñ¼ÇסÃÜÂë"/> <TextView android:layout_marginLeft="100dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Íü¼ÇÃÜÂë?" android:textSize="15dp" android:textColor="@color/black" />> </LinearLayout> </LinearLayout>

有几个问题需要补充:

1.背景图片和图标图片

我们一般将图片资源保存到res–>>drawable-hdpi 文件中。 所以<ImageView 标签里面的android:src="@drawable/bg1“和 android:background="@drawable/bg3" 需要自行保存图片到res–>>drawable-hdpi 文件

2.颜色的设置 关于代码中android:textColor="@color/black" 这一些设置,我们是在res–>>values 文件中新建了一个color.xml的资源文件。 代码如下

<?xml version="1.0" encoding="utf-8"?> <resources> <color name="red">#ff0000</color> <color name="orange">#ff7d00</color> <color name="yellow">#ffff00</color> <color name="green">#00ff00</color> <color name="cyan">#00ffff</color> <color name="blue">#0000ff</color> <color name="purple">#ff00ff</color> <color name="black">#000000</color> <color name="white">#ffffff</color> </resources>

3.关于如何新建一个文件.xml文件 我们右击我们需要新建文件的目录选择new -->>Android XML File -->>在file的框中填入一个以字母开头的名字即可。


如果还有问题欢迎留言提问。


最新回复(0)