Inner padding of a Text with Jetpack Compose - android

In the UI design of a screen, I have a very big text (180 sp). To follow the design though I need to have just a 16 dp padding around the text, including the inner vertical padding of the text. The problem is that even if I put a padding of 0 dp the inner padding is already bigger than 16 dp
Is there a way to set to 0 the inner vertical padding of a Text with Jetpack Compose?

Actually that is innate, it follows material guidelines. If you wish to disable it, an alternative would be to look at the source of Text. You could just copy the source and make modifications to meet your requirements. It is doable, and is a recommended practice to customize behavior for your needs.

Related

Android MotionLayout custom attribute methodName

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

What Design is Material?

I have a TabLayout which it's height is 50dp. each tab inside it contains both icon and title inside itself. But as this article says If I use both icon and title inside a tab, TabLayout height should be 72dp. now my question is :
if I set 50dp for my TabLayout's height, Will go out my design from Material Design? Thanks
sorry about my English.
All sizes mentioned in Material.io are required to respect Material Design Guideline.
Well, Material Design is just a set of guidelines based on some research. It suggests good practices and consistent solutions. Material Design guidelines used to be pretty strict, for example when it comes to shapes of buttons, because they wanted to make users used to some concepts. With Material Design 2 the guidelines relaxed a lot.
Minimal size is meant to keep items distinguishable and accessible, but still not too big. I wouldn't make tabs much smaller, because it may look squashed. It won't affect the usability though as minimal size for clickable items is 40dp, I guess. You would probably need to reduce spacings and sizes of other items in your app in order to make it look consistent with shorter tabs.
Changing font is fine as long as it was designed for on-screen reading. The size can be any as well as long as text is large enough to be readable.
If your design is consistent, items are distinguishable, easy to use and aligned well, then you're good. Take a look at Material Studies on material.io - these designs show how far you can go without breaking anything.

ConstraintLayout performance - Guidelines vs Margins

I'm using ConstraintLayout in most of my layouts, and I want to know what's the best practice in the performance aspect:
Using a guideline as a view's limit, including as a margin limit.
Example: 4 guidelines in total, no margins.
guideline picture
Using a view margin, which will result in less accurate spacing, because I will need to insert an arbitrary number of dps.
example: 2 guidelines in total, 2 margins (top + bottom)
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
margins picture
If you have another option, I will be happy to read it.
Also, I would like to know how to track performance of layout configuration such as this (where have you looked / what have you used to give me the answer).
Thanks.
In this case, you can get the same result without guidelines. Percent dimensions can be used in ConstraintLayout.
Just set the "layout_constraintHeight_default" attribute to "percent" (to use percentage units), and set the percentage using "layout_constraintHeight_percent". (width related attributes are available too)
As for the layout performance between 4 widgets, and, 2 widgets and 2 constraints(margins). I am sure that the latter will do better as it takes a smaller layout to render.
However, in this case, the difference is insignificant.

How to handle accessibility zoom / font size changes?

When I modify accessibility settings zoom and font size in Android my app layout is all broken.
I'can't find information about good practice to avoid this.
Most of my screen are not lists and are not scrollable, I have a bottom area with button, and in the middle I have complete layout with text fields / buttons / input / ...
Font size is too big so the text gets clipped vertically and horizontally.
Buttons don't fit in the width and display one over the other.
Do I have to manage this with different layouts depending on screen size?
Is there a way to automatically truncate text with "..."?
Is there a way to prevent some part of my layout to zoom (ex navigation part / lower button area)?
How do I prevent view from displaying one over the other (I use contraint layout)?
If I had to take a guess though, you probably are using a constraint or relative layout and haven't made the appropriate adjustments for all the child objects.
For truncating, try looking here - Android: TextView automatically truncate and replace last 3 char of String
For font sizes, it's recommended to use "sp" for the unit type, e.g. "15sp".
For constraint layouts, you need to set the anchors for each child object or they end up bunching up in the middle together.
this is a tutorial on constraint layouts - https://codelabs.developers.google.com/codelabs/constraint-layout/index.html?index=..%2F..%2Fio2018#0

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.

Categories

Resources