2012-04-14 49 views
1

我正在編寫一個應用程序,該應用程序應該在按鈕等下面的屏幕底部的畫布中繪製一條線。我的佈局顯示出來,但是該線不顯示。任何人都知道爲什麼我的畫布不顯示?爲什麼我的畫布不會顯示(Android)?

下面是代碼:

public class Vectors extends Activity{ 

VectorsView vectorsView; 
LinearLayout l; 

public void onCreate(Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.vectors);   
    vectorsView = new VectorsView(this); 
    l = (LinearLayout) findViewById(R.id.llCanvasV); 
    l.addView(vectorsView); 

    ....... 
} 

public class VectorsView extends View{ 

    public VectorsView(Context context) { 
     super(context); 
    } 
    @Override 
    protected void onDraw(Canvas canvas) { 
     // TODO Auto-generated method stub 
     super.onDraw(canvas);  

     Paint paint = new Paint(); 
     paint.setColor(Color.WHITE); 

     canvas.drawLine(0, 0, 100, 100, paint); 
     vectorsView.draw(canvas); 
     vectorsView.setLayoutParams(new LayoutParams(25, 25)); 
    } 
} 

下面是XML:

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/background" 
    android:orientation="vertical"> 

    <ImageView android:layout_height="wrap_content" 
     android:src="@drawable/vectors" 
     android:layout_width="wrap_content" 
     android:layout_gravity="center" 
     android:paddingTop="5dp" 
     android:paddingBottom="5dp" 
     android:adjustViewBounds="true"> 
    </ImageView> 
    <LinearLayout android:layout_height="wrap_content" 
     android:layout_width="match_parent" 
     android:orientation="horizontal"> 
     <Button android:text="Choose Program" 
      android:id="@+id/bChsProgV" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="5dp" 
      android:layout_marginLeft="97dp" 
      android:adjustViewBounds="true"> 
     </Button> 
     <ImageButton android:layout_height="wrap_content" 
      android:src="@drawable/help" 
      android:id="@+id/ibHelpV" 
      android:layout_width="wrap_content" 
      android:layout_marginLeft="65dp" 
      android:background="@null" 
      android:layout_marginTop="10dp"> 
     </ImageButton> 
    </LinearLayout> 
    <LinearLayout android:id="@+id/llCanvasV" 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent"> 
    </LinearLayout> 
</LinearLayout> 

回答

0

onMeasure方法在VectorsView類失蹤。也可以通過保留完整包<package.VectorsView android:id= android:width= android:height= ></package.VectorsView>

從佈局中添加VectorsView
相關問題