Android MotionLayout custom attribute methodName - android

What is the usage of custom attribute in MotionLayout "methodName"?
an example will be great :-)
I'm looking for a good solution for cases where I've a textView and I need to change the fontFamily or gravity when it's not supported by MotionLayout.

MethodName and custom method allows you to call Methods that are not in the standard set and get
Usually associated with
for example:
<KeyTrigger motion:framePosition="60"
motion:motionTarget="#+id/button" motion:onNegativeCross=".">
<CustomMethod motion:methodName="performHapticFeedback" motion:customIntegerValue="3"/>
</KeyTrigger>
Generally the TextView is not design with animation and would not give you what you are looking for.
For example gravity, Change it would not animate the text to the new position because they are positions
Animation of FontFamily etc is also not easy.
To change things like that you really have 2 choices:
Cross fading between two textView
Use MotionLabel which is limited but was designed with animation in mine.
MotionLabel
MotionLabel has the limitation of only supporting a single line of text
But provides a rich set of attributes you can use to animate
for example instead of gravity with its limited "start" "center" etc.
It supports textPanX and textPanY where textPanX=0.0 is center, -1.0 is left justified, and +1.0 right justified.
allowing you to smoothly pan from center to left.
It also support scaleFromTextSize to allow you to set a base text size which the text will scale from. Animating the text size will cause loading a different font on each frame.
For more information on MotionLabel the see the GitHub

Related

Dynamic ellipsis support for Android autosizing TextViews

The new Autosizing TextViews are pretty awesome, but it seems a fundamental thing is missing: ellipses.
Adding ellipses still requires defining the maxLines attribute, but if I want to be able to dynamically resize the text size according to the text view boundaries, I'd also like to be able to dynamically add ellipses when needed. Right now, if the text doesn't fit even with the minimum text size, it just gets cropped.
How could I add support for dynamic ellipses without giving up the new autosizing support?
The best solution I came up with so far was to programmatically set the maxLines to the proper value on runtime. Something like this will get the job done:
fun TextView.setMaxLinesForEllipsizing() = doOnPreDraw {
val numberOfCompletelyVisibleLines = (measuredHeight - paddingTop - paddingBottom) / lineHeight
maxLines = numberOfCompletelyVisibleLines
}
Be aware that this depends on Android KTX (but can also be easily achieved with a regular OnPreDrawListener).
Then we can simply call this extension from any TextView we want to get the dynamic ellipsis.
textView.setMaxLinesForEllipsizing()
If the text changes it might be necessary to call it again, though. So it might also possible to reach a more complete (and complicated) solution by moving this logic to a custom TextView and maybe overriding onTextChanged() there.

How to find dimensions for Material Design UI Elements?

When trying to pick padding and width and margin for UI elements, I see that some default values pop up in the XML. This makes me think --> Is there a standard set of measurements that I can use for material design instead of trying to guess what looks right?
Like in the picture below, where specifically in the documentation can i find the list of all dimensions available?
Android specifies certain widths and heights that you should use for your application. For example the horizontal and vertical activity margins, the padding in TextView or EditText. See https://material.google.com/layout/metrics-keylines.html for the guidelines.

Is there something like Android's match parent in Delphi?

I want to have components in my android app that will match their parent's size, but I can't find it in the object inspector.
If I use align and anchors it works almost similar, but it's still not as good as android's design.
The easiest way is to use Align property.
If you want your child control to fill the parent's entire client area, set the Align to Client. Note this one does not cover the parent control's borders. You probably know about this one from VCL where it was named alClient.
If you want your child control to cover the entire parent control, including its borders and such, set Align to Contents. This one is a new option that was introduced to FMX and is not available in VCL.
You can read more about Align options in the oficial documentation:
FMX.Controls.TControl.Align
FMX.Types.TAlignLayout

Set objects from rigth to left in titanium

I'm developing android application using Titanium 3.X. I need to add an image and a label (name) in a way that label is next to the image in same row and both should be right aligned. The problem is label text which represent a name is dynamic. So I can't set right property for the image view. I need to do this in a way which compatible with different devices (Screen sizes). I have given my font size as 11dp.
right property for image can be calculated by some algorithm which accepts font size, device screen width etc. But I couldn't identify it. Can anyone suggest me a way to resolve this ?
In this situation, I would add a view to wrap the image and label. I would set the view's layout to horizontal. I would then right align the view.
You should use a layout that will do the computations for you.
The RelativeLayout is quite useful in such situations. When you construction it in XML there are attributes like alignParentRight or layout_toRightOf that should prove useful. Don't forget to set the width of the TextView as wrap_content.

Preventing Pixelation of Images, indenting listViews and adding Rounded corners

I have a few issues and questions regarding some UI development on Android. Firstly look at this image:
Firstly at image A) This is a image that I insert and repeat horizontally to give the zig-zag shape at the top of the screen regardless of screensize and above that a textField with no content and a background color - But as I'm sure you can is that the two colors don't match up quite as perfectly as it should even though they both have the same hex color value (#BF0426). And secondly, you can also see some serious pixelation on that zig-zag image. How do I fix these 2 problems?
And then at image B) Here I have a simple listView. What I would like to do, is firstly indent it a bit on both sides, and round the corners of the top and bottom item. So basically I want it to look like the blue border drawn on the screenshot. (Your typical iOS listView). How do I go about doing this?
Thanks in advance for any tips!
For the image. Just out of curiosity, why wouldnt you simply extend your image to include the top pixels as well? In other words, build your repeating image such that it incorporates the pixels that you are trying to create using the empty textview. This will at least take care of the color missmatch, as the color will all be generated from the same place. In terms of the pixelation. Are you truly repeating the image, or are you spreading the image. A spreading will definitely cause what you are seeing.
For your tableview:
For the left and right indent, you can simply use the margin or padding attributes of tableview item. There are generic padding and/or margin attributes (which will pad all of the top, bottom, left and right), or there are separate padding and/or margin attributes for each top, bottom, left, and right. Here is a great link on padding versus margin that you may want to read.
Difference between a View's Padding and Margin
Example attribute (as called in an XML file) for bottom margin
android:layout_marginBottom
setMargins(left, top, right, bottom) // for setting margins programmatically
Example attribute (as called in an XML file) for top padding
android:paddingTop
setPadding(left, top, right, bottom) // for setting padding programmatically
For the custom top and bottom, you should be able to use the following tutorial
http://www.softwarepassion.com/android-series-custom-listview-items-and-adapters/
From here, you should be able to detect the item as the first and last item and set the background property (image) to a background image that has a rounded top or rounded bottom. This is how I do it on the iPhone. I have also implemented things that LOOK like tableviews but are simply vertical layouts with my own custom views that I have made to look like what you are wanting.
One thing to consider is the file format you use is going to mutate the image as you save it (lossy compression), so a .jpg with a certain color may look different than a .bmp with the same color. Make sure you author using the same application and/or export settings when trying to match up images.
Also, if you created your image with a DPI that is not compatible with the android display it can cause serious pixelation in detail areas, especially with gradients and drop shadows.

Categories

Resources