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(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
PlotViewhas zero size, you need to implementonMeasure(int, int)to determine the size it should need for drawing as explained here.You might also need to set some
LinearLayout.LayoutParamsfor it since you’re adding the view to theLinearLayoutthrough code.