四、 ImageView:
只有是View的子类,都可以使用setOnClickListener作为监听器,监听事件
- src(给ImageView指定一张图片):
android:src="@drawable/img_1"/>
private ImageView imageView;
imageView = findViewById(R.id.image_view);
imageView.setImageResource(R.drawable.img_2);
- ScaleType是定义在ImageView上用来呈现图片的不同显示
[图片上传失败...(image-8517c5-1558102675702)]
src和background的区别:
- src:就是ImageView中内容填充的资源
- background:表示成ImageView的背景显示
- src是浮在background的上方的
ImageButton和ImageView的区别:
- 一般使用ImageButton来响应控件的点击效果,使用ImageView来呈现一个图片的控件
- 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的其他属性:
- maxWidth:最大宽度
- maxHeight:最大高度
- adjustViewBounds:(true/false)在使用最大高度和最大宽度时,要配合使用此属性,因为只用当设置adjustViewBounds="ture"的时候,maxWidth/maxHeight设置效果才能有效。
具体效果:[https://www.jianshu.com/p/13de1774471c] - tint:给图片着色
【注】android中,将活动设置为只为横屏的的属性:
在Manifeat中,给活动添加android:screenOrientation="landscape"
网友评论