Android User Interface1:View&移动终端软件开发课程&StudyAccount2 2018.9.11

###1.View
Android所有控件全都继承自View类,(需要在.java文件中导入android.view.View;)具有所有的View属性。
视图的继承关系

####1.1TextView:用来显示文本信息
ex:

 <TextView
        android:id="@+id/textView1"//表示该控件的id,在布局文件中或者代码中被引用
        android:layout_width="match_parent"//填满父控件
        android:layout_height="wrap_content"//裹住内容,不设置具体值
        android:text="@string/easy_text"
        android:gravity="center_vertical"//设置文本纵向居中
        android:paddingLeft="5dip"//设置内边距
        android:layout_marginTop="5dip"//设置外边距
        android:textColor="@color/colorPrimaryDark"/>

#####wrap_content&wrap_content&fill_parent的区别:

  • wrap是根据容器内的东西决定组件的大小,比如一个按钮,按钮中的字体大,那么这个按钮就大,字体小那么相应的按钮就会小些。
  • match的话是指“填充满”父容器。但是他跟fill_parent是不一样的,fill是真的填满,没有条件。而match的话有自动调整的功能
    #####android:text=”@string/easy_text”—— android:textColor=”@color/colorPrimaryDark”
  • 表示显示的文本信息是strings.xml中name=easy_text的内容,文本颜色是colors.xml中name=colorPrimaryDark的颜色
  • 另一种写法是android:text=”你们好”;android:textColor=”#303F9F”(不推荐)
    1
    2
    ####1.2 EditView:用来编辑输入的文本信息
    <EditText
        android:id="@+id/editText2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="密码"//表示在输入之前的提示
        android:SingleLine="ture"//文本输入框不可换行输入,只能在一行内输入文本
        android:inputType="textPassword"
        />

#####android:inputType=”textPassword”

  • 表示输入框是用来输入密码的,输入的文本会自动变为“.”,起到隐藏用户密码的作用。
  • 另一种写法是android:password=”true”
    ####1.3Button:按钮组件
    <Button
        android:id="@+id/button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:onClick="ButtonClick"
        android:text="登录" />

#####android:onClick=”ButtonClick”

  • 该属性在源代码中设置一个ButtonClick方法,作为该Button的点击监听方法
  • 实现监听还可以调用findViewById(int id)找到该Button,后续文章会应用的
    3

1.4ImageView:展示图片

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="5"
        android:scaleType="center"//表示图片以何种形式填充到View对应的矩形区域
        android:src="@drawable/cat" />//设置填充的图片
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值