• AbsoluteLayout xiantu



    xiantu.java

    public class xiantu extends Activity
    {
      /*声明对象变量*/
      private ImageView mImageView;
      private Button mButton;
      private TextView mTextView;
      private String fileName="/data/data/irdc.ex04_22/ex04_22_2.png";
      
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState)
      {
        super.onCreate(savedInstanceState);
        /* 载入main.xml Layout */
        setContentView(R.layout.main);
        
        /* 取得Button对象,并添加onClickListener */
        mButton = (Button)findViewById(R.id.mButton);
        mButton.setOnClickListener(new Button.OnClickListener()
        {
          public void onClick(View v)
          {
          /* 取得对象 */
            mImageView = (ImageView)findViewById(R.id.mImageView);
            mTextView=(TextView)findViewById(R.id.mTextView);
            /* 检查文件是否存在 */
            File f=new File(fileName);   
            if(f.exists()) 
            { 
              /* 产生Bitmap对象,并放入mImageView中 */
              Bitmap bm = BitmapFactory.decodeFile(fileName);
              mImageView.setImageBitmap(bm);
              mTextView.setText(fileName); 
            } 
            else 
            {  
              mTextView.setText("此文件不存在"); 
            }
          } 
        });
      }
    }

    main.xml

    <?xml version="1.0" encoding="utf-8"?>
      <AbsoluteLayout
        android:id="@+id/layout1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/white"
        xmlns:android="http://schemas.android.com/apk/res/android"
      >
        <TextView 
          android:id="@+id/mTextView" 
          android:layout_width="fill_parent"  
          android:layout_height="wrap_content"  
          android:text="@string/str_text"
          android:layout_x="30px"
          android:layout_y="30px"
          android:textColor="@drawable/blue"
        >
        </TextView> 
        <ImageView
          android:id="@+id/mImageView"
          android:layout_width="250px"
          android:layout_height="188px"
          android:src="@drawable/example060"
          android:layout_x="30px"
          android:layout_y="62px"
        >
        </ImageView>
        <Button
          android:id="@+id/mButton"
          android:layout_width="155px"
          android:layout_height="wrap_content"
          android:text="@string/str_button"
          android:textSize="18sp"
          android:layout_x="80px"
          android:layout_y="302px"
        >
        </Button>
      </AbsoluteLayout>
    








  • 相关阅读:
    表达式与运算符
    Python3 从零单排22_异常处理
    Python3 从零单排21_元类
    Python3 从零单排20_方法(绑定&内置)&反射
    Python3 从零单排19_组合&多态
    Python3 从零单排18_封装
    Python3 从零单排17_类的继承
    Python3 从零单排16_面向对象基础
    Python3 从零单排15_urllib和requests模块
    Python3 从零单排14_flask模块&mysql操作封装
  • 原文地址:https://www.cnblogs.com/flyingsir/p/3983750.html
Copyright © 2020-2023  润新知