What's the difference between LinearLayout and LinearLayoutCompat

后端 未结 1 1874
面向向阳花
面向向阳花 2021-02-12 11:37

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

1条回答
  •  广开言路
    2021-02-12 12:17

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

    0 讨论(0)
提交回复
热议问题