I am trying to build a custom view but there seems to be something that I am not getting.
I have overriden the onSizeChanged and onDraw methods and added my custom view in the activity layout and given it a height of say 100dp and pinned it to the bottom and start and end of the parent relative layout. However the view doesn't render correctly and there is a blank empty space beneath it.
below is my onDraw and onSizedChanged methods
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
viewHeight = h;
viewWidth = w;
}
@Override
protected void onDraw(Canvas canvas) {
// draw background
painter.setStrokeWidth(viewHeight);
painter.setColor(Color.BLUE);
canvas.drawLine(0, 0, viewWidth, 0, painter);
}
below is how I am adding the view to the layout xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_registration"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.example.activities.RegistrationActivity">
<com.example.custom.widgets.MyCustomView
android:id="@+id/holder"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="100dp"/>
<FrameLayout
android:layout_above="@+id/holder"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:text="kjdgfjkasdgfjkahsdgfjkhsa"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
</RelativeLayout>
FWIW, I also trying embedding my custom view inside a FrameLayout and explicitly setting the height of the FrameLayout and setting the height of my custom view to match_parent. still no success.