Android查看帮助

时间:2010-08-06 19:37:28

标签: android android-emulator android-manifest

我正在尝试使用setContentView(R.layout.main)从活动中显示主屏幕;然后显示如下图像:

公共类TryGraph扩展了Activity {

/** 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显示它。

1 个答案:

答案 0 :(得分:0)

添加视图时,应使用addView版本,该版本允许您提供LayoutParams以配置视图在布局中的显示方式。请参阅LayoutParams