I am usin开发者_Python百科g an AbsoluteLayout for a Activity and have it defined in a xml file.
I added this line of code because I am trying to add a list of buttons dynamically and I get the following warning.
private AbsoluteLayout layout = (AbsoluteLayout) findViewById(R.id.viewsaved);
The type AbsoluteLayout is deprecated
The code still appears to work properly, but I was just curious to see if anyone knows why this warning appears?
Thanks for any help!
In computer software or authoring programs standards and documentation, the term deprecation is applied to software features that are superseded and should be avoided. Although deprecated features remain in the current version, their use may raise warning messages recommending alternative practices, and deprecation may indicate that the feature will be removed in the future. Features are deprecated—rather than being removed—in order to provide backward compatibility and give programmers who have used the feature time to bring their code into compliance with the new standard.
From Wikipedia - Deprecation
In short, the function will work for now but will likely be removed in future versions. You'll want to find something to replace it with.
AbsoluteLayout suggests you use FrameLayout
, RelativeLayout
or a custom layout instead.
It appears because it is deprecated. You should not use AbsoluteLayout
anyway, it was deprecated for a good reason.
The reason is that it does not allow automatic handling of multiple screen sizes which is a very important aspect of Android.
Deprecated code is code that is still in the release for backwards compatibility reasons (ie for old programs to use) but has been superceeded by a newer and better peice of code.
For a list of buttons I would recommend either a ListView
or a LinearLayout
as these will allow you to add items in a list format. If you need to use AbsoluteLayout
for its positioning then you're going to need to be more inventive with your use of LinearLayout
s and RelativeLayout
s
Means that it is marked for removal and will be gone in some future version of Android. From http://developer.android.com/reference/android/widget/AbsoluteLayout.html
This class is deprecated. Use FrameLayout, RelativeLayout or a custom layout instead.
In most Java libraries, especially the very popular ones, the maintainers try very hard to make sure if you make code against an old version of the library that it won't break with a newer version (backward compatability.)
However, sometimes they realize they have made mistakes that are fundamental to the library in general and cannot be fixed. In this case, they deprecate. It means "yes it will work exactly like it did before, but be warned: there is a serious flaw in it." Typically, they follow this up with a suggested replacement.
In a related note, while I haven't done Android, I have done a lot of Java gui development. It's so tempting to say "I'll just use absolute positioning. I have no problem keeping track of everything." But as your program grows, sure enough it gets so difficult to keep it all in check. Only now, you have tons of code that has to be refactored to change it into a more maintainable layout. Don't fall into that trap: use a good layout manager from the start!
精彩评论