2

So I have been using Contraint Layout since it seems to be much more powerful than Relative layout. However, I noticed that the support library has Percent Relative Layout Which seems to be very usable in many situation (specifying that the width of image view needs to be 30% of screen width).

If you have layout where you need to place things in relation to each other and have the sizes to be based on percentage, is it bad approach to use PercentRelativeLayout?

Thanks

Snake
  • 14,228
  • 27
  • 117
  • 250
  • 1
    It's deprecated. https://developer.android.com/reference/android/support/percent/PercentRelativeLayout.html – OneCricketeer Jun 16 '17 at 22:14
  • Possible duplicate of [Differences between ConstraintLayout and RelativeLayout](https://stackoverflow.com/questions/37321448/differences-between-constraintlayout-and-relativelayout) – Vidhi Dave Jun 17 '17 at 04:08

1 Answers1

2

is it bad approach to use PercentRelativeLayout?

Yes, insofar as it will be deprecated when the v26 edition of the support libraries are released in production form, later in 2017.

That doesn't stop you from using it with the v25 edition of the libraries. However, typically you need to keep moving to newer versions of those libraries, so you will need v26 eventually.

Since ConstraintLayout can handle most, if not all, of the PercentRelativeLayout scenarios, there is little value in starting to use PercentRelativeLayout now.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • @Snake: The percent classes are about two years old IIRC. I imagine that Google does not want to maintain them anymore. If you want to keep using them, one possibility is to simply grab the latest source code and package your own standalone library with them. – CommonsWare Jun 16 '17 at 22:24
  • 2
    to do percent positioning and sizing with Constraint layout, we need to use so many guidelines and the XML can quickly become complicated and overwhelming. While percent layout simplifies it greating by limiting the info to the view itself so really constraint layout lack the core Function percent relative layout. I guess, like you said we can keep using them but the general advice is to go with new versions – Snake Jun 17 '17 at 06:42
  • 2
    @Snake: `ConstraintLayout` 1.1 [supports percent directly](https://medium.com/@rafael_toledo/whats-new-in-constraint-layout-1-1-x-f0bdd4dbdfb3). – CommonsWare Jun 17 '17 at 10:48
  • relativelayout is deprecated now. – filthy_wizard Feb 21 '18 at 13:21
  • 2
    @filthy_wizard: `RelativeLayout` is not deprecated. `PercentRelativeLayout` is deprecated. – CommonsWare Feb 21 '18 at 13:27
  • oh cool. seems to be flaging it as deprecated for me in android studio? – filthy_wizard Feb 21 '18 at 13:35
  • @filthy_wizard: I cannot reproduce that, using Android Studio 3.0.1 and a new project (`compileSdkVersion 26` or `27`). – CommonsWare Feb 21 '18 at 13:39
  • I think @filthy_wizard was just making a joke; sad to see PercentRelativeLayout deprecated! :( – swooby Feb 28 '18 at 23:45