如何动态设置ImageView的宽高以及位置
2016-04-11 17:48
274 查看
[html] view
plain copy
print?
package com.pic;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
public class PicTest extends Activity {
private final String TAG = "Pictrue Test!!!";
private ImageView image;
private int height = 0;
private int width = 0;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
image = (ImageView)findViewById(R.id.ImageView01);
//height = image.getHeight();
//width = image.getWidth();
//Log.d(TAG, "height: " + height);
//Log.d(TAG, "width: " + width);
LayoutParams para;
para = image.getLayoutParams();
Log.d(TAG, "layout height0: " + para.height);
Log.d(TAG, "layout width0: " + para.width);
para.height = 300;
para.width = 300;
image.setLayoutParams(para);
Log.d(TAG, "layout height: " + para.height);
Log.d(TAG, "layout width: " + para.width);
}
}
plain copy
print?
package com.pic;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
public class PicTest extends Activity {
private final String TAG = "Pictrue Test!!!";
private ImageView image;
private int height = 0;
private int width = 0;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
image = (ImageView)findViewById(R.id.ImageView01);
//height = image.getHeight();
//width = image.getWidth();
//Log.d(TAG, "height: " + height);
//Log.d(TAG, "width: " + width);
LayoutParams para;
para = image.getLayoutParams();
Log.d(TAG, "layout height0: " + para.height);
Log.d(TAG, "layout width0: " + para.width);
para.height = 300;
para.width = 300;
image.setLayoutParams(para);
Log.d(TAG, "layout height: " + para.height);
Log.d(TAG, "layout width: " + para.width);
}
}
相关文章推荐
- 为什么在 linux 中程序运行要分为用户态和内核态?
- [Java] 02 String的常用方法
- ASP.NET-常用插件集合
- 浅谈Android程序与JavaScript脚本的交互
- 回顾大学里坚持的一段时期的日记,以及现阶段的思考
- C++作业3—本月有几天/定期存款利息计算器/个人所得税计算器
- opencv多线程拷贝视频文件到内存然后再写到本地
- 分布式之_多线程之指定线程运行服务器
- Java多线程学习(吐血超详细总结)
- 数据结构-线性表的链式结构
- PHP memcache 安装问题
- E/dalvikvm( 2456): ERROR: couldn't find native method
- flex学习进度5
- hdoj1242 Rescue
- 深入详解多线程第一篇_多线程笔试面试题汇总
- Masonry的使用(二)
- 监听器
- 进程与线程的区别?
- 数组排序
- HTML 5 Web Sockets应用初探