I have created a custom view in which a bitmap is drawn. The problem is that the custom view takes up the whole screen regardless of the layout width/height I set it or it's parent.
I have been going through the forums and I read about overriding the onmeasure method, but for me that returns zero so now the width and height are set to zero.
Here is what I have done so far:
EDIT
FULL xml:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:sliderView="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black">
<RelativeLayout
android:id="@+id/cameraLayout"
android:layout_width="wrap_content"
android:background="@color/black"
android:layout_height="wrap_content">
<SurfaceView
android:layout_alignParentTop="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/surfaceview">
</SurfaceView>
<LinearLayout
android:layout_above="@+id/beerName"
android:id="@+id/beerColours"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/beer1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/beer1"
android:layout_weight="1"/>
<ImageView
android:id="@+id/beer2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/beer2"
android:layout_weight="1"/>
<ImageView
android:id="@+id/beer3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/beer3"
android:layout_weight="1"/>
<ImageView
android:id="@+id/beer4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/beer4"
android:layout_weight="1"/>
<ImageView
android:id="@+id/beer5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/beer5"
android:layout_weight="1"/>
<ImageView
android:id="@+id/beer6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/beer6"
android:layout_weight="1"/>
</LinearLayout>
<EditText
android:background="@color/black"
android:id="@+id/beerName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:layout_above="@+id/seperator"
android:hint="@string/beer_name"
android:textColorHint="@color/white"
android:gravity="center_horizontal"
/>
<ImageView
android:id="@+id/seperator"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/dotted_separator"
android:layout_above="@+id/sliderViewLayout"/>
<RelativeLayout
android:id="@+id/sliderViewLayout"
android:layout_above="@+id/bottomsUp"
android:background="@color/black"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.test.bottomsup.custom_slider_library.sliderView
android:layout_marginLeft="15dp"
android:id = "@+id/sliderview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
sliderView:diagonalSlide="false"
sliderView:translateAxisX="false"
/>
<ImageView
android:id="@+id/slider_frame"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/glass"
android:layout_centerHorizontal="true"
android:layout_alignParentLeft="true">
</ImageView>
</RelativeLayout>
<com.test.bottomsup.custom.Components.ShadyButton
android:id="@+id/bottomsUp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/button_red"
android:textColor="@color/white"
android:text="@string/button_bottoms_up"
android:layout_alignParentBottom="true" />
</RelativeLayout>
</RelativeLayout>
In my fragment where I set the custom view is a follows:
sliderView slider = (sliderView)view.findViewById(R.id.sliderview);
slider.setImageResource(R.drawable.beer_with_arrows);
slider.requestLayout();
Then in my custom view class I call onMeasure as follows:
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int wrapHeight = getWidth();
int wrapWidth = getHeight();
this.setMeasuredDimension(wrapHeight, wrapWidth);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
wrapHeight and wrapWidth are returned as zero. Could anyone offer some advice? I'm new to custom views etc so I'd appreciate the dig out ;)
****EDIT**** I should add that this is a slider, so in my custom view I am using the onscroll method...I imagine that might change things. So I have a frame image under which my view is scrolled, so I guess I need to set the height of my view to twice the frame height??
Can anyone help?
layout structure