安卓知识点罗列

Android界面编程

视图

RelativeLayout对齐方式:

<TextView android:id=”@+id/lblComments”android:layout_width=”wrap_content” android:layout_height=”wrap_content”android:text=”Comments”android:layout_alignParentTop=”true”android:layout_alignParentLeft=”true” /><EditText android:id=”@+id/txtComments”android:layout_width=”fill_parent” android:layout_height=”170px”android:textSize=”18sp”android:layout_alignLeft=”@+id/lblComments”android:layout_below=”@+id/lblComments”android:layout_centerHorizontal=”true” />

这里的alignLeft属性可以相对于TextView

相对于父控件:android:layout_alignParent+Top/Bottom/Left/Right

相对于给定id控件:android:layout_+above/below/toLeftOf/alignTop/alignBottom

LinerLayout

用于指定排列方式的属性:android:orientation="vertical/horizontal"

宽度、高度属性:fill_parent,wrap_content

EditText的文本用:hint属性

Button和其他的用:text属性

子节点排列方式:android:gravity=“center_horizontal”

FrameLayout

可以用来显示单个视图的占位符。添加到FrameLayout中的视图常常锚定在布局的左上方

<FrameLayout

android:layout_width=”wrap_content”

android:layout_height=”wrap_content”

android:layout_alignLeft=”@+id/lblComments”

android:layout_below=”@+id/lblComments”

android:layout_centerHorizontal=”true”>

<ImageViewandroid:src = “@drawable/droid”

android:layout_width=”wrap_content”

android:layout_height=”wrap_content”/>

</FrameLayout>

可以利用android:layout_gravity属性来指定其居中排列

前景照片属性

android:foreground,android:foregroundGravity,通常不会用FrameLayout显示多项内容

ConstraintLayout

所有的视图都是根据兄弟视图和父布局之间的关系来布局的,可以通过拖放操作来构建布局,而不是编辑XML(注意不要有循环依赖)

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent"

同时约定上下,就会居中

  1. 必须为视图添加至少一个水平约束条件和一个垂直约束条件,每个约束条件均定义了视图在竖轴或者横轴上的位置

字体

sp:会随着系统字体的大小改变,且能适应屏幕密度的变化

dp:不会随着系统字体的大小而改变,不能适应屏幕密度的变化

组件

文本框(TextView)

直接继承了View,还是EditText、Button两个UI组件类的父类

作用就是显示文本

android:password,可以按密文方式显示文本信息

android:selectAllOnFocus:默认选中并获得焦点

批量修改多个文本框

利用循环遍历,先将所有控件Id,和所有控件需要显示的文字在数组中存入,再利用循环。

输入框(EditText)

限定输入类型:android:inputType

限定行数:android:lines

内容提示:android:hint

不仅可以输入文字,还可以是其他的照片之类的

按钮(Button)

点击相应:android:onClick=“onLogin”

保证按钮之间的互斥

用RadioGroup,然后包含RadioButton即可

<RadioGroup..........android:id="@+id/rg">

<RadioButton..........android:id="@+id/rb_a"android:text="A:125"/>

<RadioButton..........android:id="@+id/rb_b"android:text="B:100"/>

<RadioButton..........android:id="@+id/rb_c"android:text="C:175"/>

<RadioButton..........android:id="@+id/rb_d"android:text="D:200"/>

</RadioGroup>

判断哪一个按钮被选中

利用isChecked()属性即可。

事件监听器的方式

图像框(ImageView)

同样有onClick属性,设置背景用android:background

代码栏:imageView.setBackgroundResource(R.drawable.bg1)

XML中src和background的区别
  1. background 会根据 ImageView 组件给定的长宽进行拉伸,而 src 就存放的是原图的大小,不会进行拉伸

  1. src 是图片内容(前景), bg 是背景,可以同时使用。

  1. scaleType 只对 src 起作用; bg 可设置透明度

网格视图(GridView)

stretchMode属性值的作用是设置GridView中的条目以什么缩放模式去填充剩余空间。
填充图像的步骤
    • 0
      点赞
    • 0
      收藏
      觉得还不错? 一键收藏
    • 0
      评论

    “相关推荐”对你有帮助么?

    • 非常没帮助
    • 没帮助
    • 一般
    • 有帮助
    • 非常有帮助
    提交
    评论
    添加红包

    请填写红包祝福语或标题

    红包个数最小为10个

    红包金额最低5元

    当前余额3.43前往充值 >
    需支付:10.00
    成就一亿技术人!
    领取后你会自动成为博主和红包主的粉丝 规则
    hope_wisdom
    发出的红包
    实付
    使用余额支付
    点击重新获取
    扫码支付
    钱包余额 0

    抵扣说明:

    1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
    2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

    余额充值