imageView的使用(进行原样的保持和按照比例的缩放:)

布局文件:

android:scaleType  

fitCenter就是按照比例进行缩放,设置好了这一项之后,那么android:layout_width 和 height就开始起作用了。

center就是不缩放。

设置图片的来源:android:src="@drawable/background"


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:orientation="vertical" android:layout_width="fill_parent"
	android:layout_height="fill_parent">
	<TextView android:layout_width="fill_parent"
		android:layout_height="wrap_content" android:text="scaleType:center 为缩放,放在ImageView的中心" />
	<ImageView android:id="@+id/imageview" android:layout_width="wrap_content"
		android:layout_height="wrap_content" android:background="#F00"
		android:src="@drawable/background" android:scaleType="center"></ImageView>

	<TextView android:layout_width="fill_parent"
		android:layout_marginTop="20dp" android:layout_height="wrap_content"
		android:text="scaleType:fitCenter 按照比例缩放" />

	<ImageView android:id="@+id/imageview2" android:layout_width="300dp"
		android:layout_height="200dp" android:background="#FFF"
		android:src="@drawable/background" android:scaleType="fitCenter"
		android:padding="10dp"></ImageView>
</LinearLayout>



代码:

设置整个布局的参数:

setlayoutparams 


package com.example.marvinedittext2;


import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class Main extends Activity {
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		ImageView imageView = (ImageView) this.findViewById(R.id.imageview); 
		// 设置第一个图片的比例大小
		// 表示宽度:200高度是100
		imageView.setLayoutParams(new LinearLayout.LayoutParams(200, 100));
		setTitle("height:" + imageView.getLayoutParams().height + "--width-->>"
				+ imageView.getLayoutParams().width);
	}
}

总结:就是直接用xml文件包装了一个图片文件,然后在用代码直接加载这个xml文件。然后直接用于显示。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值