Horizo​​ntalScrollView中的画布

时间:2015-07-28 12:33:30

标签: android canvas horizontalscrollview

我遇到了Canvas不在Horizo​​ntalScrollView中绘制的问题。相反,我得到一个空白的屏幕。但是如果我们添加任何其他对象,那么一切都运行得很完美。我有人有这个吗?

这是我的Point.class

public class Point extends View implements Serializable {

    private float x;
    private float y;
    private Paint paint = new Paint();

    public Point(Context context) {
        super(context);
        paint.setColor(Color.BLUE);
        paint.setStrokeWidth(5);

    }

    public float getX() {
        return x;
    }

    public void setX(float x) {
        this.x = x;
    }

    public float getY() {
        return y;
    }

    public void setY(float y) {
        this.y = y;
    }

    @Override
    public void onDraw(Canvas canvas){
        super.onDraw(canvas);
        canvas.drawCircle(getX(), getY(), 5f, paint);
    }
}

我的Field课程,我想要显示我的分数

public class GraphicField extends RelativeLayout {

    private RelativeLayout scrollLayout;

    public GraphicField(Context context) {
        super(context);

        LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = layoutInflater.inflate(R.layout.graph_field, this);

        scrollLayout = (RelativeLayout) view.findViewById(R.id.scrollLayout);

        init();
    }

    private void init() {
        Point point = new Point(getContext());
        point.setX(10);
        point.setY(10);
        scrollLayout.addView(point);
        point = new Point(getContext());
        point.setX(200);
        point.setY(200);
        scrollLayout.addView(point);
    }
}

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white">

    <LinearLayout
        android:id="@+id/leftLayout"
        android:layout_width="10dp"
        android:layout_height="match_parent"
        android:layout_marginBottom="10dp"
        android:gravity="right"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="10dp">

        <View
            android:layout_width="2dp"
            android:layout_height="match_parent"
            android:background="@color/blue_dark" />
    </LinearLayout>

    <HorizontalScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_toRightOf="@+id/leftLayout"
        android:fillViewport="true">

        <RelativeLayout
            android:id="@+id/scrollLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="2dp"
                android:layout_alignParentBottom="true"
                android:layout_marginBottom="10dp"
                android:layout_marginRight="10dp"
                android:background="@color/blue_dark"
                android:minWidth="1000dp" />
        </RelativeLayout>
    </HorizontalScrollView>


</RelativeLayout>

如果我将Horizo​​ntalScrollView替换为RelativeLayout,则完美显示点。请帮助别人

0 个答案:

没有答案