I got a problem with an modified android layout. After I extends the normal relative layout so that it will be automatically square sized, all embedded other views will disappear.
<namespace.SquareRelativeLayout
android:layout_weight="1"
android:id="@+id/firstBtn"
android:background="#ff0000"
android:clickable="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/firstBtnImage"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/firstBtnDrawable" />
<TextView
android:id="@+id/firstBtnLabel"
android:layout_alignParentBottom = "true"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginBottom="10dp"
android:textColor="#ffffff"
android:text="@string/firstBtnlabel"
android:textStyle="bold" />
</namespace.SquareRelativeLayout>
But Text view and Image view were not shown, even they were anywhere at the screen.
I am be thankful for every hind.
Edit:
namespace namespace
{
class SquareRelativeLayout : RelativeLayout
{
public SquareRelativeLayout (Context context, IAttributeSet attrs, int defStyle) : base (context, attrs, defStyle)
{
}
public SquareRelativeLayout (Context context, IAttributeSet attrs) : base (context, attrs)
{
}
public SquareRelativeLayout (Context context) : base (context)
{
}
protected override void OnMeasure (int widthMeasureSpec, int heightMeasureSpec)
{
//Get canvas width
int w = MeasureSpec.GetSize (widthMeasureSpec);
base.SetMeasuredDimension (w, w);
}
}
}