android学习之展示图片资源
来源:互联网 发布:数据编程是什么工作了 编辑:程序博客网 时间:2024/06/06 00:06
在大家所使用的android应用中除了文本信息外还有图片信息,而在咱们的android开发过程中为用户展示图片信息,我们通常会使用ImageView,将单词拆开来翻译一下,就很明白图片视图,顾名思义,ImageView是用来显示图片内容的。
在布局当中我们如果想要使用这个控件首先就要将它写到我们的布局容器当中:
布局文件代码如下:
<?xml version="1.0"encoding="utf-8"?>
<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"
/>
</RelativeLayout>
当前代码显示效果为:
而如果我们为ImageView指定了死的宽高为match_parent时ui界面如图:
而其实我们还可以进一步的对图片的展示进行调整:
通过修改android:scaleType的属性值开控制控件的显示:如果将ImageView的代码改为:
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:scaleType="centerInside"
android:layout_height="match_parent"
android:src="@drawable/ic_launcher" />
那么,当前的显示效果为:
android:scaleType的值共8种,但不需要记忆,当你需要对图片的显示效果进行调整时你可以将这几个值换着来,看调试的效果。
接下来是通过代码设置指定的图片信息展示:
首先你可以将一张你想要展示的图片拷贝到Drawable目录里,但要注意它的命名:
不要有大写字母,不要有空格,不要以数字开头,不要是纯数字,不要有特殊符号,确认图片名称符合标准时,我们将图片拷贝到Drawable目录,
然后在我们的java源文件中代码:
import android.os.Bundle;
import android.app.Activity;
import android.widget.ImageView;
import android.widget.TextView;
public class MainActivity extends Activity{
ImageViewimage;
@Override
protectedvoid onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.image);
//找到ImageView
image=(ImageView)findViewById(R.id.image);
//设置展示指定的图片信息
image.setImageResource(R.drawable.login);
}
}
- android学习之展示图片资源
- Android使用Drawable资源之使用ClipDrawable资源 实现图片缓慢展示
- Android中图片的展示之Webview居中显示图片
- Android基础学习,使用Drawable资源之ClipDrawable资源,实现图片在特定位置展开。
- Android展示gif图片
- Android超长图片展示
- 【Android 界面效果30】Android中ImageSwitcher结合Gallery展示SD卡中的资源图片
- Android之使用ViewPager实现图片展示(最简单的)
- Android学习 13 -> 图片资源ImageView
- android学习之 resources资源
- android学习之resources资源
- android学习之resources资源
- android学习之resources资源
- android之资源优化处理---图片压缩
- Android中ImageSwitcher结合Gallery展示SD卡中的资源图片
- Android中ImageSwitcher结合Gallery展示SD卡中的资源图片
- Android中ImageSwitcher结合Gallery展示SD卡中的资源图片
- Android中ImageSwitcher结合Gallery展示SD卡中的资源图片
- 使用Maven 整合Spring和hibernate 适合初级接触的学者
- 设计模式之适配器模式
- Codeforces 697A. Pineapple Incident (模拟)
- 百度地图应用开发基本配置
- static inline内联函数
- android学习之展示图片资源
- oracle表分区详解
- tomcat系统架构简介
- [iOS开发]关于cocoapods的使用
- Netty 作为服务器端源代码剖析
- 关于js与android方法互调的问题
- Android WIFI热点应用
- APP开发实战86-View动画
- STM32F1学习-驱动led灯(库函数版本)