1

I'm trying to set the widht on 50% on an androiyd layout file this way

 android:layout_width="50%"

but I get this error

Error:(49, 39) Fraction types not allowed (at 'layout_width' with value '50%').

How I have to set the width on 50%?

AFS
  • 1,433
  • 6
  • 28
  • 52

3 Answers3

0

Are you using Percentage layout? If so try this

 app:layout_widthPercent = "50%"
Stackover67
  • 347
  • 2
  • 4
  • 18
0

You need to use a library for this, since Android does not supply this by default. You might either need a or a PercentRelativeLayout or a PercentFrameLayout depending on your root layout.

Check this thread below:

How to use Percentage for android layout?

Edit, thanks to @Eugene

This was deprecated in Android 8.0 and up, you can use a ConstraintLayout as well, as described here.

https://developer.android.com/reference/android/support/percent/PercentFrameLayout.html

gi097
  • 7,313
  • 3
  • 27
  • 49
0

Recently you were able to do it with PercentFrameLayout and PercentRelativeLayout, but since they were deprecated in 26.0.0 the convenient way to set percentage value to your layout_width is to use guidelines which were introduced in ConstraintLayout

Here's my answer on another question on how to set percentage value https://stackoverflow.com/a/45865283/7158449

Eugene Brusov
  • 17,146
  • 6
  • 52
  • 68