Android 刷新线性布局大小

Android 刷新线性布局大小,android,xamarin,xamarin.android,Android,Xamarin,Xamarin.android,我想在我的应用程序中有一个方形imageview,我制作了一个自定义imageview: namespace Blood_Pressure_Notebook.Widget { public class SquareImageView : ImageView { public int SquareMode { get; set; } = 0; public SquareImageView(Context context) : base(context) {

我想在我的应用程序中有一个方形imageview,我制作了一个自定义imageview:

namespace Blood_Pressure_Notebook.Widget
{
    public class SquareImageView : ImageView
    {
        public int SquareMode { get; set; } = 0;

    public SquareImageView(Context context) : base(context) { }
    public SquareImageView(Context context, IAttributeSet attrs) : base(context, attrs)
    {
        Android.Content.Res.TypedArray ta = Context.ObtainStyledAttributes(attrs, Resource.Styleable.SquareImageView);
        this.SquareMode = ta.GetInt(Resource.Styleable.SquareImageView_SquareMode, 0);
        ta.Recycle();
    }
    public SquareImageView(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer) { }

    protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
    {
        base.OnMeasure(widthMeasureSpec, heightMeasureSpec);
        if (SquareMode == 0)
        {
            SetMeasuredDimension(MeasuredWidthAndState, MeasuredWidthAndState);
        }
        else if (SquareMode == 1)
        {
            SetMeasuredDimension(MeasuredHeight, MeasuredHeight);
        }
    }
}
}

我在这里使用它:

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
                                        xmlns:app="http://schemas.android.com/apk/res-auto"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_gravity="center"
      app:cardElevation="2dp"
      app:cardCornerRadius="1dp"
      app:cardPreventCornerOverlap="true"
      app:cardUseCompatPadding="true"
      app:contentPadding="0dp">
      <LinearLayout
          android:orientation="vertical"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content">
        **<LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layoutDirection="rtl">
          **<blood_pressure_notebook.widget.SquareImageView
              android:src="@android:drawable/ic_menu_gallery"
              android:layout_width="0dp"
              android:layout_height="wrap_content"
              android:id="@+id/imgImage"
              android:scaleType="centerInside"
              android:layout_weight="0.2" 
              android:adjustViewBounds="true"
              app:SquareMode="0"/>**
          <TextView
              android:text="Medium Text"
              android:textAppearance="?android:attr/textAppearanceMedium"
              android:layout_width="0dp"
              android:layout_height="wrap_content"
              android:id="@+id/txtName"
              android:layout_gravity="start|center_vertical"
              android:layout_weight="0.8"
              android:textSize="@dimen/textSize" />
        </LinearLayout>**
        <TextView
            android:text="Medium Text"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:id="@+id/txtDescription" />
        <RelativeLayout
            android:minWidth="25px"
            android:minHeight="25px"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/relativeLayout1">
          <ImageView
              android:src="@drawable/ic_account_box_black_24dp"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:id="@+id/imgLogin"
              android:layout_alignParentEnd="true" />
          <ImageView
              android:src="@drawable/ic_mode_edit_black_24dp"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:id="@+id/imgEdit"
              android:layout_alignParentStart="true" />
        </RelativeLayout>
      </LinearLayout>
    </android.support.v7.widget.CardView>

**
****
**
imageview的大小更改没有任何问题,但其父级(LinearLayout)的高度不会更改并保持较大

我的问题是如何刷新或更新LinearLayout

我尝试了Invalidate()和设置LayoutParameter,但没有任何更改