如何滚动我的自定义视图?我想查看屏幕边界上绘制的形状

发布于 2024-10-18 13:24:10 字数 2139 浏览 2 评论 0原文

我有一个自定义视图...

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.AttributeSet;
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);

    }
}

使用这个简单的配置文件:

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

在我的视图中,我想滚动以查看在屏幕边界上绘制的形状..

我该怎么做?

问候, 安东尼奥·穆塞拉

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.AttributeSet;
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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ぶ宁プ宁ぶ 2024-10-25 13:24:10
<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>
<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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文