閱讀869 返回首頁    go 阿裏雲 go 技術社區[雲棲]


AbsoluteLayout 相框


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:
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  xmlns:andro
  >
  <ImageView
  android:
  android:layout_width="320px"
  android:layout_height="280px"
  android:layout_x="0px"
  android:layout_y="36px"
  />
  <ImageView
  android:
  android:layout_width="104px"
  android:layout_height="157px"
  android:layout_x="101px"
  android:layout_y="119px"
  />
  <Button
  android:
  android:layout_width="105px"
  android:layout_height="66px"
  android:text="圖片1"
  android:layout_x="9px"
  android:layout_y="356px"
  />
  <!--建立第二個Button -->
  <Button
  android:
  android:layout_width="105px"
  android:layout_height="66px"
  android:text="圖片2"
  android:layout_x="179px"
  android:layout_y="356px"
  />
</AbsoluteLayout>













最後更新:2017-04-02 16:48:16

  上一篇:go java中一個漢字和一個字母所占內存字節比較以及後台驗證的減半處理
  下一篇:go spring使用中報Cannot proxy target class because CGLIB2 is not available錯