1

変更された Android レイアウトで問題が発生しました。通常の相対的なレイアウトを拡張して自動的に正方形のサイズになるようにすると、埋め込まれた他のすべてのビューが消えます。

      <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>

しかし、テキスト ビューとイメージ ビューは、画面のどこにあっても表示されませんでした。

私はすべてのハインドに感謝しています。

編集:

   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);
        }
    }
}
4

1 に答える 1