2010-08-06 139 views
0

我想要使用setContentView(R.layout.main)在活動中顯示主屏幕;然後已如下的圖像顯示:Android查看幫助

公共類TryGraph延伸活動 {

/** Called when the activity is first created. */ 


public LinearLayout mLinearLayout; 

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    // Create a LinearLayout in which to add the ImageView 
    mLinearLayout = new LinearLayout(this); 

    // Instantiate an ImageView and define its properties 
    ImageView i = new ImageView(this); 
    i.setImageResource(R.drawable.face3); 
    i.setAdjustViewBounds(true); // set the ImageView bounds to match the Drawable's dimensions 

    mLinearLayout.addView(i); 
    setContentView(mLinearLayout); 

} 
} 

main.xml中是這樣

  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 

      android:orientation="vertical" 

      android:layout_width="fill_parent" 

      android:layout_height="fill_parent" 

      > 
      <TextView 
      android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="@string/hello" 
       /> 

     <Button android:text="button" android:id="@+id/Button01" 

      android:layout_width="wrap_content"    
     android:layout_height="wrap_content"></Button> 

按鈕被隱藏通過圖片,因爲它是在按鈕頂部繪製的。如何在不同的地方在飛行中放置圖片,以便顯示按鈕和圖片。注意:我不想從xml顯示圖片,我想從LinearLayout顯示它。

回答

0

添加視圖時,應該使用addView的版本,該版本允許您提供LayoutParams以配置視圖在佈局中的顯示方式。見LayoutParams

+0

http://stackoverflow.com/questions/3442331/draw-view-on-image-within-xml – 2010-08-09 18:03:01