开发者

android drawing lines on horizontal scroll view

hello i have released my iphone app Micro-Pitch and am now porting it to android. I cannot figure out how to draw lines in a scroll view and am wondering what i am doing wrong.

here is the part of my interface with the scroll view

<HorizontalScrollView android:id="@+id/scroll_view" android:layout_above="@+id/btn_info" android:layout_alignParentTop="true" android:layout_height="match_parent" android:layout_width="match_parent" android:overScrollMode="always" android:layout_alignParentRight="true" android:layout_alignParentLeft="true">
            <LinearLayout android:layout_height="match_parent" android:id="@+id/scroll_layout" android:layout_width="match_parent">
            </LinearLayout>
        </HorizontalScrollView>

this is my plot_view class

public class PlotView extends View
{
    Paint paint = new Paint();

    public PlotView(Context context)
    {
        super(context);
        paint.setColor(Color.RED);
    }

    @Override
    public void onDraw(Canvas canvas) {
            canvas.drawLine(0, 0, 200, 200, paint);
            canvas.drawLine(20, 0, 0, 20, paint);
    }
}

and this is the segment of my main activity class

HorizontalScrollView scroll_view;
LinearLayout scroll_layout;
PlotView plot_view;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    scroll_view= (HorizontalScrollView)findViewById(R.id.scroll_view);
    scroll_layout= (LinearLayout)findViewById(R.id.scroll_layout);

    plot_view = new PlotView(this);
    plot_view.setBackgroundColor(Color.WHITE);
    scroll_layout.addView(开发者_C百科plot_view);
}

The plotview is not even showing up on the scroll view

If possible please take a look a my iphone version of the app its free. What im doing this for is plotting the sound on the scroll view. that way you can get a better sense of what i am trying to do.


Your PlotView has zero size, you need to implement onMeasure(int, int) to determine the size it should need for drawing as explained here.

You might also need to set some LinearLayout.LayoutParams for it since you're adding the view to the LinearLayout through code.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜