开发者

How can I scroll my custom view? I want to see the shapes drawn over the bounds of the screen

I have a Custom view ...

package nan.salsa.goal.customview;

import android.R;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.RectShape;
import android.util.Attribute开发者_StackOverflowSet;
import android.util.Log;
import android.view.View;

public class DayView extends View {

    private static String TAG="DayView";

    private ShapeDrawable mDrawable;

    public DayView(Context context) {
        super(context);
    }

    public DayView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public DayView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();
    }

    public void init() {

        int x = 10;
    int y = 10;


    mDrawable = new ShapeDrawable(new RectShape());
    mDrawable.getPaint().setColor(Color.GREEN);
    mDrawable.setBounds(x, y, x + (width - (x * 2)), y + (height - (y*2)));

    mDrawable.draw(canvas);
    for (int i = 1; i < 30; i++) {
        boxDrawable = new ShapeDrawable(new RectShape());
        boxDrawable.setBounds(x + x , y + (100 * i) , x + (width - ((x + x) * 2)), y + (100 * i) + 50);
        boxDrawable.getPaint().setColor(Color.RED);
        boxDrawable.draw(canvas);
    }



    }

    @Override
    protected void onDraw(Canvas canvas) {
        // TODO Auto-generated method stub
        super.onDraw(canvas);
        setBackgroundColor(R.color.black);
        mDrawable.draw(canvas);

    }
}

with this simple configuration file :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:background="#E06F00">

    <nan.salsa.goal.customview.DayView android:id="@+id/dayView"
        android:layout_height="match_parent" 
        android:layout_width="fill_parent" />


</LinearLayout>

In my view I want to scroll to see the shapes drawn over the bounds of the screen ..

How I can do it?

Regards, Antonio Musella


<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#E06F00">
    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <nan.salsa.goal.customview.DayView
            android:id="@+id/dayView"
            android:layout_height="match_parent"
            android:layout_width="fill_parent" />
    </ScrollView>
</LinearLayout>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜