Android开发学习经历(三)

现在我对xml有了更近一步的了解的,在使用过不少APP后我觉得UI设计的好坏直接影响用户数量的,现在总结一下常用控件的使用方法。MianActivity代码如下:

?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/wukong"
>
<TextView
android:id="@+id/hellow"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginTop="225dp"
android:text="加油"
android:textColor="#ffff0000"
android:textSize="40dp" />
<Button
android:id="@+id/button"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignTop="@+id/hellow"
android:layout_marginLeft="40dp"
android:layout_marginStart="40dp"
android:layout_marginTop="67dp"
android:background="@drawable/button" />
</RelativeLayout>

运行效果如图

1.RelativeLayout支持控件可以自己设置位置,而LinearLayout不支持。每个控件的基本用法都是先设置一个ID,然后再设置长和宽,细节上还可以自己进一步设置。

2.APP所用到的图片都应加入到res下的drawable文件夹中,android:background=”@drawable/使用的图片名字”来设置图标或界面的背景。

3 . 官方更推荐使用match_parent,表示让当前控件的大小和父布局一样。

4.在xml中添加了按钮后还应该在Activity中添加点击事件的监听器来实现按钮的功能,当你按下时就会执行监听器的onClick()的方法。

5.还有几个控件没有写详细的代码,如ImageView是在界面上展示图片的控件。ProgressBar在界面上显示进度条。AlertDialog是在当前界面上弹出提示对话框。

猜你喜欢

转载自blog.csdn.net/qq_38055347/article/details/80033682