从零开始学android<ImageView和ImageButton的使用.十.>
来源:互联网 发布:中科大还有网络教育吗 编辑:程序博客网 时间:2024/06/08 16:10
ImageView组件的主要功能是为图片展示提供一个容器,android.widget.ImageView类的定义如下:
java.lang.Object
↳android.view.View
↳android.widget.ImageView
常用方法
No.
配置属性名称
对应方法
描述
1
android:maxHeight
public void setMaxHeight (int maxHeight)
定义图片的最大高度
2
android:maxWidth
public void setMaxWidth (int maxWidth)
定义图片的最大宽度
3
android:src
public void setImageResource (int resId)
定义显示图片的ID
当然imageview里面还有许多设置图片的方法,大家可以自己在以后的开发中去看看…………………………………………………………毫无美感的分割线…………………………………………………………
选择res下的drawable-hdip文件夹,将转备好的图片放入
然后定义 xml文件
<RelativeLayout 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=".MainActivity" > <ImageView android:layout_width="wrap_content"//宽度包裹内容 android:layout_height="wrap_content"//高度包裹内容 android:src="@drawable/bg"//设置图片 /></RelativeLayout>
运行效果:
…………………………………………………………毫无美感的分割线…………………………………………………………
ImageButton和imageView基本类似,只不过ImageButton多了事件监听机制,和其他的一些操作
与按钮组件(Button)类似,在Android中又提供了一个图片按钮,可以直接使用ImageButton定义,此类定义如下:
java.lang.Object
↳android.view.View
↳android.widget.ImageView
↳android.widget.ImageButton
<RelativeLayout 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=".MainActivity" > <ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/abc" /></RelativeLayout>
上图就是imageButton的显示效果
这节讲的比较简单,大家可以参照APi获得更多的方法。
下节预报:时间选择器:TimePicker
0 0
- 从零开始学android<ImageView和ImageButton的使用.十.>
- ImageButton和ImageView的使用
- Android学习笔记十:基本视图组件:ImageView和ImageButton
- android:ImageView 和ImageButton的区别
- Android中ImageView和ImageButton
- Android中的ImageView和ImageButton
- android组件ImageView和ImageButton无法正常使用
- ImageView和ImageButton的区别
- Android中使用selector动态改变imageView或ImageButton的背景和在GridView中应用
- Android中使用selector动态改变imageView或ImageButton的背景和在GridView中应用
- Android中ImageView和ImageButton的比较详解
- 一步一步学android之基本控件——ImageView和ImageButton组件
- Button的使用(十):ImageButton
- 第9章、图像按钮ImageButton(从零开始学Android)
- 第9章、图像按钮ImageButton(从零开始学Android)
- 第9章、图像按钮ImageButton(从零开始学Android)
- 第9章、图像按钮ImageButton(从零开始学Android)
- Android之ImageButton、ImageView
- UVa 11646 Athletics Track
- win8 win8.1 升级 Update1 无法完成更新 解决方法
- Little and Big Endian
- 20140410-1 翻译学习作品
- Pascal's Triangle -- LeetCode
- 从零开始学android<ImageView和ImageButton的使用.十.>
- Pascal's Triangle II -- LeetCode
- Evaluate Reverse Polish Notation
- Python3.2官方文档教程---Set集合
- 水货的学习笔记之~java的按需输入与输出
- python 保存HTML时UTF-8问题
- Eclipse安装Maven插件
- 地方的第三方的身份的身份斯蒂芬
- [POJ 1639] 单度限制最小生成树