Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between LinearLayout and LinearLayoutCompat

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 LinearLayoutand LinearLayoutCompat?

like image 979
max Avatar asked Oct 08 '16 10:10

max


People also ask

What is 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.

What is difference between LinearLayout and RelativeLayout?

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.

What is difference between Framelayout and LinearLayout?

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.

What is LinearLayout?

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.


1 Answers

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, ...).

like image 101
reVerse Avatar answered Sep 19 '22 13:09

reVerse