美文网首页
【Android】ImageView控件笔记

【Android】ImageView控件笔记

作者: 感同身受_ | 来源:发表于2019-05-17 22:18 被阅读0次

    四、 ImageView:

    只有是View的子类,都可以使用setOnClickListener作为监听器,监听事件

    1. src(给ImageView指定一张图片):
      android:src="@drawable/img_1"/>
    private ImageView imageView;
    imageView = findViewById(R.id.image_view);
    imageView.setImageResource(R.drawable.img_2);
    
    1. ScaleType是定义在ImageView上用来呈现图片的不同显示
      [图片上传失败...(image-8517c5-1558102675702)]

    src和background的区别:

    1. src:就是ImageView中内容填充的资源
    2. background:表示成ImageView的背景显示
    3. src是浮在background的上方的

    ImageButton和ImageView的区别:

    1. 一般使用ImageButton来响应控件的点击效果,使用ImageView来呈现一个图片的控件
    2. ImageButton继承自ImageView

    在LinearLayout中,当两个Button相邻时,想让他们分别位于左右两端

    捕获6.PNG

    使用weight(可帮助布局)

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
    
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button1"/>
    
            <View
                android:layout_width="0dp"
                android:layout_height="1px"
                android:layout_weight="1"/>
    
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button2"/>
        </LinearLayout>
    
    
    捕获7.PNG
    ImageView的其他属性:
    1. maxWidth:最大宽度
    2. maxHeight:最大高度
    3. adjustViewBounds:(true/false)在使用最大高度和最大宽度时,要配合使用此属性,因为只用当设置adjustViewBounds="ture"的时候,maxWidth/maxHeight设置效果才能有效。
      具体效果:[https://www.jianshu.com/p/13de1774471c]
    4. tint:给图片着色

    【注】android中,将活动设置为只为横屏的的属性:
    在Manifeat中,给活动添加android:screenOrientation="landscape"

    相关文章

      网友评论

          本文标题:【Android】ImageView控件笔记

          本文链接:https://www.haomeiwen.com/subject/xmmaaqtx.html