zoukankan      html  css  js  c++  java
  • 动态设置ImageView的宽高以及位置

    如何动态设置ImageView的宽高以及位置

    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);

    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 " + para.width);

    }

    }另外一种方法是 RelativeLayout.LayoutParams param = new RelativeLayout.LayoutParams(dm.widthPixels, dm.heightPixels/2-30);

    top_image.setLayoutParams(param);

    摘自:http://www.01yun.com/mobile_development/20130321/258529.html

  • 相关阅读:
    Tomcat配置
    Tomcat介绍和jbk安装
    nginx企业级优化
    linux 部署lnmp平台
    linux nginx服务
    linux rsync
    openssh远程连接及tcpwrappers防护
    linux 日志文件系统
    linux 解析文件系统原理
    linux 安全配置二
  • 原文地址:https://www.cnblogs.com/veins/p/4103204.html
Copyright © 2011-2022 走看看