zoukankan      html  css  js  c++  java
  • View(视图)

    一.事件

    概念:

    事件源:事件发起者,也就是视图组件

    事件:事件源产生的动作,并包含相关信息

    监听器:

    是一些关于事件处理的接口
    负责拦截和处理事件信息
    要实现相关监听器的接口,把处理事件的业务逻辑写在回调方法里
    要把监听器的实现类的实例和事件源进行关联

    回调方法:

    负责处理事件
    由监听器监听到事件之后自动调用

    二.实现方式

    1-自动关联方式:
    在layout文件里,给视图添加onClick=方法名
    在java文件里,写onClick的方法,必须有传入参数(View v)
    只支持onClick
    可以重用
    2-匿名内部类:
    在setOnxxxListener(new 监听器接口的实现类)
    不能重用
    3-普通内部类:
    能够重用
    能直接访问Activity内部的组件
    4-普通外部类:
    能够重用
    不能直接访问Activity内部的组件
    适合全局公用的并且不需要直接操作内部组件的事件监听
    5-Activity实现类:
    由Activity自身去实现监听器接口   
    setOnxxxListener(this)
    能直接访问Activity内部的组件
    容易造成代码混乱

    三.单选按钮

    四.图片按钮

    按钮上不能添加文字
    src 图片来源
    ImageButton

    五.图片视图

    ImageView
    src 图片来源
    scaleType 显示属性:
    center
    centerCrop
    centerInside
    matrix
    fitCenter
    fitEnd
    fitStart
    fitXY
    alphe 透明度:
    设置值为0~1
    <=0,全透明
    >=1,不透明

     

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        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.hanqi.testapp2.TestActivity1"
        android:orientation="vertical">
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/xiao1" />
        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/xiao2"/>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/xiao1"
            android:text="普通按钮"/>
        </LinearLayout>
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
        <ImageView
            android:layout_width="110dp"
            android:layout_height="110dp"
            android:src="@drawable/xiao3"
            android:alpha="1"
            android:background="#f00"
            android:scaleType="center"
            />
        <ImageView
            android:layout_width="110dp"
            android:layout_height="110dp"
            android:src="@drawable/xiao3"
            android:alpha="1"
            android:background="#f00"
            android:scaleType="centerCrop"
            />
            <ImageView
                android:layout_width="110dp"
                android:layout_height="110dp"
                android:src="@drawable/xiao3"
                android:alpha="1"
                android:background="#f00"
                android:scaleType="centerInside"
                />
        </LinearLayout>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <ImageView
                android:layout_width="110dp"
                android:layout_height="110dp"
                android:src="@drawable/xiao3"
                android:alpha="1"
                android:background="#f00"
                android:scaleType="matrix"
                />
            <ImageView
                android:layout_width="110dp"
                android:layout_height="110dp"
                android:src="@drawable/xiao3"
                android:alpha="1"
                android:background="#f00"
                android:scaleType="fitCenter"
                />
            <ImageView
                android:layout_width="110dp"
                android:layout_height="110dp"
                android:src="@drawable/xiao3"
                android:alpha="1"
                android:background="#f00"
                android:scaleType="fitStart"
                />
        </LinearLayout>
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <ImageView
                android:layout_width="110dp"
                android:layout_height="110dp"
                android:src="@drawable/xiao3"
                android:alpha="1"
                android:background="#f00"
                android:scaleType="fitEnd"
                />
            <ImageView
                android:layout_width="110dp"
                android:layout_height="110dp"
                android:src="@drawable/xiao3"
                android:alpha="1"
                android:background="#f00"
                android:scaleType="fitXY"
                />
        </LinearLayout>
    
        <RadioGroup
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
    
            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="男"/>
            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="女"/>
    
        </RadioGroup>
    
    </LinearLayout>
    一.scaleType 显示属性 二.单选按钮

  • 相关阅读:
    如何生成不规则形状的mask,以解决对图像不规则区域设置ROI的问题
    数字图像处理学习1
    opencv显示图像
    Calling Matlab Neural Network From Other EXE's
    这个百度文档很给力
    opencv不规则ROI——圆形ROI
    问题修改
    skinsmagic美化MFC界面
    第一次使用思维导图
    libsvm使用介绍中文版
  • 原文地址:https://www.cnblogs.com/cycanfly/p/5460615.html
Copyright © 2011-2022 走看看