2010-08-06 140 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