1

我正在编写一个程序,该程序应该在屏幕底部按钮下方的画布中绘制一条线,等等。我的布局出现了,但这条线没有。有谁知道为什么我的画布没有出现?

这是代码:

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>
4

1 回答 1

0

onMeasureVectorsView 类中缺少方法。并且您还可以通过保留完整的包从布局中添加 VectorsView<package.VectorsView android:id= android:width= android:height= ></package.VectorsView>

于 2012-04-14T02:16:00.997 回答