I know LinearLayoutCompat
was realized to give us some newer methods which were added in a higher levels of android to lower levels of Android.
My problem is this method:
linearLayout.setPaddingRelative
Which was added in API 17 but we should have it in lower API by using the following code right?
linearLayoutCompat.setPaddingRelative
But my Android Studio still shows the following error on it.
Call requires API level 17 (current min is 15): android.view.View#setPaddingRelativ
So what's the difference between LinearLayout
and LinearLayoutCompat
?
LinearLayoutCompat was added to support methods which were added in newer API levels on old ones (like dividers). If you compare the methods in LinearLayout and LinearLayoutCompat you can see that the Compat layout has all methods of the LinearLayout without any API level limitation.
LinearLayout : is a ViewGroup that aligns all children in a single direction, vertically or horizontally. RelativeLayout : is a ViewGroup that displays child views in relative positions.
Frame Layout: This is designed to block out an area on the screen to display a single item. Linear Layout: A layout that arranges its children in a single column or a single row. Relative Layout: This layout is a view group that displays child views in relative positions.
LinearLayout is a view group that aligns all children in a single direction, vertically or horizontally. You can specify the layout direction with the android:orientation attribute. Note: For better performance and tooling support, you should instead build your layout with ConstraintLayout.
LinearLayoutCompat
was added to support methods which were added in newer API levels on old ones (like dividers). If you compare the methods in LinearLayout and LinearLayoutCompat you can see that the Compat layout has all methods of the LinearLayout without any API level limitation.
This brings us back to your question: You are trying to use a method which is part of the View class (LinearLayout
inherits from the View
class). The supported methods of the View class depend on the different API levels that's why you can't use this method before API level 17 neither with the LinearLayout nor the LinearLayoutCompat.
If you want to use this method no matter what API level you're on you can use the ViewCompat class and call ViewCompat.setPaddingRelative(View view, ...)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With