• ImageView相关


    ImageViewActivity.java

    package src.com;

    import android.app.Activity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.ImageView;

    public class ImageViewActivity extends Activity {

    /* 声明 Button、ImageView对象 */
    private ImageView mImageView01;
    private ImageView mImageView02;
    private Button mButton01;
    private Button mButton02;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    /* 取得 Button、ImageView对象 */
    mImageView01 = (ImageView) findViewById(R.id.myImageView1);
    mImageView02 = (ImageView) findViewById(R.id.myImageView2);
    mButton01 = (Button) findViewById(R.id.myButton1);
    mButton02 = (Button) findViewById(R.id.myButton2);

    /* 设置ImageView背景图 */
    mImageView01.setImageDrawable(getResources().getDrawable(R.drawable.right));
    mImageView02.setImageDrawable(getResources().getDrawable(R.drawable.oa));

    /* 用OnClickListener事件来启动 */
    mButton01.setOnClickListener(new Button.OnClickListener(){

    @Override
    public void onClick(View v) {
    /* 当启动后,ImageView立刻换背景图 */
    mImageView01.setImageDrawable(getResources().getDrawable(R.drawable.right));
    }

    });

    mButton02.setOnClickListener(new Button.OnClickListener(){

    @Override
    public void onClick(View v) {
    /* 当启动后,ImageView立刻换背景图 */
    mImageView01.setImageDrawable(getResources().getDrawable(R.drawable.left));
    }

    });
    }
    }

    main.xml

    <?xml version="1.0" encoding="utf-8"?>
    <AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/widget34" >"

    <!-- 建立第一个ImageView -->
    <ImageView
    android:id="@+id/myImageView1"
    android:layout_width="320px"
    android:layout_height="280px"
    android:layout_x="0px"
    android:layout_y="36px" />
    <!-- 建立第二个ImageView -->
    <ImageView
    android:id="@+id/myImageView2"
    android:layout_width="104px"
    android:layout_height="157px"
    android:layout_x="101px"
    android:layout_y="119px" />
    <!-- 建立第一个Button -->
    <Button
    android:id="@+id/myButton1"
    android:layout_width="105px"
    android:layout_height="66px"
    android:text="pic1"
    android:layout_x="9px"
    android:layout_y="356px" />
    <!-- 建立第二个Button -->
    <Button
    android:id="@+id/myButton2"
    android:layout_width="105px"
    android:layout_height="66px"
    android:text="pic2"
    android:layout_x="179px"
    android:layout_y="356px" />

    </AbsoluteLayout>

  • 相关阅读:
    oracle 分析函数3
    oracle 分析函数4
    oracle 分析函数2
    postgres
    博客系统
    Java 笔试面试 算法编程篇 一
    Java 笔试面试 基础篇 一
    Struts2
    mysql 数据类型
    ExceptionDemo
  • 原文地址:https://www.cnblogs.com/xingmeng/p/2421590.html
Copyright © 2020-2023  润新知