AbsoluteLayout 相框

简介: xiangkuang.java public class xiangkuang extends Activity{ /*声明 Button、ImageView对象*/ private ImageView mImageView01; private ImageView mImageView02; private Button mButton01; private


xiangkuang.java

public class xiangkuang 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.aaa));
    
    /*用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)
     {
      mImageView01.setImageDrawable(getResources().
                   getDrawable(R.drawable.left));
     }
   });
    
  }
}

main.xml

<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
  android:id="@+id/widget34"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  xmlns:android="http://schemas.android.com/apk/res/android"
  >
  <ImageView
  android:id="@+id/myImageView1"
  android:layout_width="320px"
  android:layout_height="280px"
  android:layout_x="0px"
  android:layout_y="36px"
  />
  <ImageView
  android:id="@+id/myImageView2"
  android:layout_width="104px"
  android:layout_height="157px"
  android:layout_x="101px"
  android:layout_y="119px"
  />
  <Button
  android:id="@+id/myButton1"
  android:layout_width="105px"
  android:layout_height="66px"
  android:text="图片1"
  android:layout_x="9px"
  android:layout_y="356px"
  />
  <!--建立第二個Button -->
  <Button
  android:id="@+id/myButton2"
  android:layout_width="105px"
  android:layout_height="66px"
  android:text="图片2"
  android:layout_x="179px"
  android:layout_y="356px"
  />
</AbsoluteLayout>













目录
相关文章
|
Android开发 容器
TableLayout(表格布局)
前面我们已经学习了平时实际开发中用得较多的线性布局(LinearLayout)与相对布局(RelativeLayout),其实学完这两个基本就够用了,这一节我们会学习Android中的第三个布局:TableLayout(表格布局)!
90 0
|
容器
RelativeLayout(相对布局)
LinearLayout也是我们用的比较多的一个布局,我们更多的时候更钟情于他的weight(权重)属性,等比例划分,对屏幕适配还是帮助蛮大的;但是使用LinearLayout的时候也有一个问题,就是当界面比较复杂的时候,需要嵌套多层的LinearLayout,这样就会降低UI Render的效率(渲染速度),而且如果是listview或者GridView上的item,效率会更低,另外太多层LinearLayout嵌套会占用更多的系统资源,还有可能引发stackoverflow;但是如果我们使用RelativeLayout的话,可能仅仅需要一层就可以完成了,以父容器或者兄弟组件参考+margi
77 0
|
算法 Java Android开发
LinearLayout(线性布局)
本节开始讲Android中的布局,今天我们要讲解的就是第一个布局,LinearLayout(线性布局),我们屏幕适配的使用用的比较多的就是LinearLayout的weight(权重属性),在这一节里,我们会详细地解析LinearLayout,包括一些基本的属性,Weight属性的使用,以及比例如何计算,另外还会说下一个用的比较少的属性:android:divider绘制下划线!
58 0
|
XML Java Android开发
android ScrollView 吸顶效果
android ScrollView 吸顶效果
302 0