0
<ImageButton
   android:src="@android:drawable/ic_menu_gallery"
   android:layout_width="308px"
   android:layout_height="560px"
   VerticalOptions="CenterAndExpand"
   HorizontalOptions="CenterAndExpand"
   android:id="@+id/imgBtn01" />

I want set VerticalOptions, HorizontalOptions in code, help me!

Saeed
  • 3,294
  • 5
  • 35
  • 52
Hoàng Huy
  • 15
  • 3

1 Answers1

1

1. Yes, there is no following properties in xamarin android:

  VerticalOptions="CenterAndExpand"
  HorizontalOptions="CenterAndExpand"

The equivalent attribute in Android is android:layout_gravity:

enter image description here

If you want use several values of property , you can use | to seperate them,just like this:

 android:layout_gravity="fill_horizontal|fill_vertical" 

2. If you want image stretch, you can use this property: android:scaleType="fitXY".You can try with centerInside if you don't want to crop your image, or centerCrop if you want to fill all the space (and cropping your image).

Here is a nice list with examples to understand better all the scaleTypes.

enter image description here:

Note:

For more details, you can check: https://developer.android.com/reference/android/widget/ImageView.ScaleType

Jessie Zhang -MSFT
  • 9,830
  • 1
  • 7
  • 19