首页 > 移动平台 > 详细

从零开始学android<ImageView和ImageButton的使用.十.>

时间:2014-04-10 08:37:53      阅读:572      评论:0      收藏:0      [点我收藏+]
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里面还有许多设置图片的方法,大家可以自己在以后的开发中去看看
…………………………………………………………毫无美感的分割线…………………………………………………………
bubuko.com,布布扣选择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>

运行效果:
bubuko.com,布布扣
…………………………………………………………毫无美感的分割线…………………………………………………………
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>

bubuko.com,布布扣
上图就是imageButton的显示效果

这节讲的比较简单,大家可以参照APi获得更多的方法。
下节预报:时间选择器:TimePicker

从零开始学android<ImageView和ImageButton的使用.十.>,布布扣,bubuko.com

从零开始学android<ImageView和ImageButton的使用.十.>

原文:http://blog.csdn.net/u013616976/article/details/23311587

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!