I am rendering a View into a Bitmap
. I need a balloon with a pointer at the top or at the bottom, based on if it fits on the screen. For that I use a RelativeLayout
, because I need the pointers to be partially over the balloon:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<LinearLayout android:id="@+id/balloon_body"
android:layout_width="@dimen/pins_details_balloon_width"
android:layout_height="wrap_content"
android:layout_marginTop="-1dp"
android:layout_marginBottom="-1dp"
android:layout_below="@+id/pointer_top"
android:orientation="vertical"
>
<TextView android:id="@android:id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
/>
<TextView android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
/>
</LinearLayout>
<ImageView android:id="@id/pointer_top"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<ImageView android:id="@+id/pointer_bottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/balloon_body"
/>
</RelativeLayout>
I inflate this view and then I want to measure and layout it, so I can render it into a bitmap:
view.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT));
//view.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT));
view.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
//view.measure(View.MeasureSpec.makeMeasureSpec(3000, View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(3000, View.MeasureSpec.AT_MOST));
view.layout(0, 0, s_View.getMeasuredWidth(), s_View.getMeasuredHeight());
This code crashes on the view.measure(...) with the Circular dependencies cannot exist in RelativeLayout error. I tried different LayoutParams (without setLayoutParams(...) the measure(...) crashes with a null pointer exception), different View.MeasureSpec-s but no success. If I remove the android:layout_below="@id/balloon_body" in the last ImageView, it works, but the bottom pointer is at the top.
I cannot use a LinearLayout, because I need those pointers to be above the body of the balloon, where with LinearLayout the top pointer will be below it. Where is the problem and how can I achieve what I want?