AbsoluteLayout xiantu

简介: xiantu.java public class xiantu extends Activity{ /*声明对象变量*/ private ImageView mImageView; private Button mButton; private TextView mTextView; private String fileName="/data/data/


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>








目录
相关文章
|
18天前
|
Android开发
Android布局——帧布局、表格布局、网格布局
Android布局——帧布局、表格布局、网格布局
|
Android开发 容器
TableLayout(表格布局)
前面我们已经学习了平时实际开发中用得较多的线性布局(LinearLayout)与相对布局(RelativeLayout),其实学完这两个基本就够用了,这一节我们会学习Android中的第三个布局:TableLayout(表格布局)!
78 0
|
容器
RelativeLayout(相对布局)
LinearLayout也是我们用的比较多的一个布局,我们更多的时候更钟情于他的weight(权重)属性,等比例划分,对屏幕适配还是帮助蛮大的;但是使用LinearLayout的时候也有一个问题,就是当界面比较复杂的时候,需要嵌套多层的LinearLayout,这样就会降低UI Render的效率(渲染速度),而且如果是listview或者GridView上的item,效率会更低,另外太多层LinearLayout嵌套会占用更多的系统资源,还有可能引发stackoverflow;但是如果我们使用RelativeLayout的话,可能仅仅需要一层就可以完成了,以父容器或者兄弟组件参考+margi
68 0
|
算法 Java Android开发
LinearLayout(线性布局)
本节开始讲Android中的布局,今天我们要讲解的就是第一个布局,LinearLayout(线性布局),我们屏幕适配的使用用的比较多的就是LinearLayout的weight(权重属性),在这一节里,我们会详细地解析LinearLayout,包括一些基本的属性,Weight属性的使用,以及比例如何计算,另外还会说下一个用的比较少的属性:android:divider绘制下划线!
52 0
|
Android开发
Android自定义View之文字居中
前言 本文讲文字的居中,不过在你阅读本文之前,强烈建议你读一下我的上一篇文章Android自定义View之DashBoard(仪表盘) ,因为上一篇的内容讲了Paint和Canvas等基础绘制的知识,你学会上一篇的内容再看现在的这篇会容易的多。
1252 0
|
Android开发 容器 数据格式