I'm updating an application where the user should be able to drag and drop some elements (buttons/imagebuttons) so that they change position, and I also need to get their X,Y coordinates.
In the previous versions I used AbsoluteLayout, even if deprecated. What could I use instead of it? Is there a real substitute?
I am a fan of RelativeLayout combined with LinearLayout; but it is all about your particular use cases.
What could I use instead of it?
Your own custom ViewGroup, that knows your business rules and that you control. Whether you create it completely from scratch, or you fork AbsoluteLayout and maintain your own fork, is up to you.
Related
In some view like AppCompatTextView we can read
This will automatically be used when you use EditText in your layouts
and the top-level activity / dialog is provided by appcompat. You
should only need to manually use this class when writing custom views.
But sometime not, like LinearLayoutCompat
So this means that we should use LinearLayoutCompat directly instead of LinearLayout ?
In case, which Compact Views is correct to use directly?
So this means that we should use LinearLayoutCompat directly instead
of LinearLayout ?
The answer is Yes.
which Compact Views is correct to use directly?
You should be able to use all the Compat views directly without any issue. AFAIK...They are built to provide more compatibility and they tend to be updated more frequently as almost all of them come from Support or AndroidX libraries which receive more frequent updates.
I am in a situation like i have to generate UI Controls like Button,Switcher,Progress Bar, Label text etc based on my list Items .
I am looking for a way to generate the controls in a View and add Views with generated controls in a Layout .
Can anyone give me a proper way to do that?
Why not to use Fragments?
Google docs about this here
and little tutorial here
You may want to take a look at the Metawidget source code. The Android version of Metawidget makes extensive use of generating Views and Layouts at runtime (e.g. see org.metawidget.android.widget.widgetbuilder.AndroidWidgetBuilder). You may even find Metawidget itself will suit your needs (it's designed to be embedded into projects for use-cases such as this).
'Android Design' site is recommending 'Boundary feedback' for scrollable view.
http://developer.android.com/design/style/touch-feedback.html
http://i.stack.imgur.com/TuBkX.png
is there any API or library for custom view to implement that with ease and consistent?
or should I implement it from the scratch?
Are you "building custom"? If you stick to the UI elements form the API you should be fine. All the scroll views can already be configured to do different things for boundry cases (such as overscroll).
If you are building UI elements from scratch, you might consider simply overriding or subclassing existing UI elements to function the way you want. If not, you can examine the source to see how different boundry cases (again overscrolling) are implemented. But, I get the feeling you're in the first category..
Does the android:clipChildren still works?
I have a AbsoluteLayout with a size and set the clipChildren to false. When I add childeren that are bigger then the AbsoluteLayout the childeren are still clipped.
Anyone got this working?
Working with Android 2.2 (API level 8)
Update 20-01-11:
I can make something similiar with a RelativeLayout, but does the android:clipChildren work on that?
btw, it's not needed that my application needs to work on any other platform then Android 2.2.
Absolute layout is deprecated. I suggest using something different.
This class is deprecated. Use
FrameLayout, RelativeLayout or a
custom layout instead.
http://developer.android.com/reference/android/widget/AbsoluteLayout.html
Edit: Answering to your comment:
Being deprecated means that for some reason, they stopped developing it. Maybe there's a better replacement, maybe they don't like the way it works. Anyway, they may drop this layout in future versions (which means your app won't be able to run in a future version of android).
Alternatives:
Frame Layout:
FrameLayout is designed to block out
an area on the screen to display a
single item. You can add multiple
children to a FrameLayout, but all
children are pegged to the top left of
the screen. Children are drawn in a
stack, with the most recently added
child on top. The size of the frame
layout is the size of its largest
child (plus padding), visible or not
(if the FrameLayout's parent permits).
Views that are GONE are used for
sizing only if
setConsiderGoneChildrenWhenMeasuring()
is set to true.
http://developer.android.com/reference/android/widget/FrameLayout.html
Relative Layout
You can also use a relative layout. Align every view by it's parent and set left and top margins as you wish. This may be your best option IMO. I've done this before and it worked reasonably well.
As Pedro said, this feature may have been an addition that came after AbsoluteLayout's deprecation, so if it's not implemented already, it will never work.
As far as the comment "which means your app won't be able to run in a future version of android", Google has promised that this will NEVER be the case.
Dianne Hackborn
On Mon, May 4, 2009 at 10:00 AM,
Sundog wrote:
I have a highly rated app that simply... could... not... be...
written... without AbsoluteLayout, no matter whose Java sensibilities
it steps on. I guess Android's doing so well with apps that it can
afford to shut down an entire category of games.
Did AbsoluteLayout disappear from 1.5?
No. Are you unable to write 1.5 apps
using it? No. Have we ever said we
have any plan to completely remove it
at any point in the future? No. You
need to find better reasons to be a
victim. If you can't find one, let
us know the name of your app and we
can make sure to break it in the next
release. Then you can -really-
complain!
-- Dianne HackbornAndroid framework engineerhack...#android.com
and later:
I'll say again: we are not going to
remove AbsoluteLayout from a future
release, but we strongly discourage
people from using it.
I'd say it's a safe bet to say it won't be removed, but it also won't get new features/fixes either.
Here is a video of my app:
It's currently using absoluteLayout, and since absoluteLayout is deprecated i decided to change my layout.
So what Layout do u suggest using for this app?
Please see the part of the video, that the game has started, that's the only part with absolutelayout.
Thanks
It really depends if you want your UI to flow in a linear fashion or not. The majority of the time I use RelativeLayout with some instances of LinearLayout here and there. Relative seems to me the most flexible for me.
"You can achieve much the same layout by using a FrameLayout instead, and setting layout_margin attributes of the children. This approach is more flexible and will yield better results on different screens."