Android:ImageView控件显示图片

本文介绍了如何在Android中使用ImageView控件显示图片,包括直接在XML布局中设置`android:src`属性和在后台代码中调用`setImageResource()`方法。此外,还提供了一个学习示例,演示了如何实现前后翻页切换图片的功能。
摘要由CSDN通过智能技术生成

1)android显示图片可以使用imageView来呈现,而且也可以通过ImageButton来实现给button添加图片。

2)在创建一个ImageView后,显示图片绑定元素是:android:src="@android:drawable/btn_dialog"

3)后台操作绑定图片函数:imgView.setImageResource(R.drawable.pic0);,其中drawable是我们可以显示工程res下所有drawable的文件夹中的图片元素的。

学习示例,实现一个前后翻页切换图片的功能:

效果:

源代码:res/layout/activity_main.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" >

    <TextView
        android:id="@+id/tvShow"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="74dp"
        android:text="" />

    <Button
        android:id="@+id/btnNext"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="54dp"
        android:
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值