Relativelayout Doesn't Draw Children If Background Is Set
I have class CalloutView extended from RelativeLayout. Currently has no any methods, it just redefines constructors. I also have an XML layout for it:
Solution 1:
I tried your code but replaced your custom layout with a RelativeLayout:
RelativeLayoutcalloutView= (RelativeLayout) ((LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.main, null);
calloutView.setLayoutParams(newRelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, 105));
calloutView.measure(MeasureSpec.makeMeasureSpec(400, MeasureSpec.AT_MOST), MeasureSpec.makeMeasureSpec(105, MeasureSpec.EXACTLY));
setContentView(calloutView);
And the xml:
<?xml version="1.0" encoding="utf-8"?><RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="70dp"android:background="@drawable/ic_launcher"><ImageButtonandroid:id="@+id/imageButton1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentRight="true"android:layout_alignParentTop="true"android:layout_marginRight="6dp"android:layout_marginTop="6dp"android:background="#ff0000"android:src="@drawable/ic_launcher"
/></RelativeLayout>
It works fine:
Therefore, this must be something about your layout. Make sure that in your redefined constructors, your call the super constructors first.
Solution 2:
It looks like a bug in Android 2.3.3. I use my PNG file as NinePatch as background, I get this issue. If I use another NinePatch, everything works like it should.
I can't reproduce this issue on Android 3.1.
Post a Comment for "Relativelayout Doesn't Draw Children If Background Is Set"