Seems like something that should be easy to find, but it's harder than I thought.
What is the default height on the TabLayout in DIPs?
Material Design guidelines state that this height equals 48dp when You have text or image, and 72dp when You have image and text.
its height is "?attr/tabIndicatorHeight"
E.g.
you can use this value in an xml file for another view like:
android:layout_marginBottom="?attr/tabIndicatorHeight"
And it will look ok on all devices.
Related
I want to use this simple layout for items of list:
Note the right gray area (which I draw red rectangle on its border in below) must be a square:
So I have to approximate the height of layout. It must be simple, but the problem is that the text size of TextViews is set by using sp unit and height of layout must be set by dp unit and I did not found a way for converting dp and sp in .xml file. Also I do not want to create a CustomView or change properties of layout at runtime. All things must be done in .xml file. How I can approximate height of layout?
See the TextSize is different from TextView's width and height.
So Provide fixed width-height to all views in "dp". Fixed Text-Size in "sp" that fits perfectly inside TextView.
P.S. -> test in a few devices/emulators to verify.
At the moment I'm playing a bit with the new ConstraintLayout and try to create the following layout:
(1) Headline: Type 24sp, Leading 32sp
(2) Subhead 1: Type 15sp, Leading 24sp
(3) 32sp line height
(4) 56dp padding between the top of button and the center of copy
(5) 24dp vertical padding
My problem now is that I do not know how I should handle the sizes which refer to the center of the second TextView. We do not have a constraint for the center (or baseline) to bottom or something like this. Also I'm not able to set a space between two views which are connected between the baseline points. So how should I create this layout with the ConstraintLayout?
Can someone please give me a sample layout from the picture above?
We only allow baseline to baseline, without margin for now. We might revisit this in the future, but as of ConstraintLayout alpha 7 you cannot do this. The only option is to align with top / bottom.
You could also add a view with a layout height as a divider, then reference the bottom of the divider
This question might be trivial to some of you.
I am facing a dumb issue working with designers and developers.
According to the designers the android button from material design has a particular style, default button style (top button in the image).
Designer defines a fix height and width 50dp for instance. So they expect to have a button of those dimensions.
But developers when using a default android button, the default button contains margins.
So we use a custom drawable background, in this case the button has the expected dimensions (button a the bottom). But the style is not exactly the same (very few differences, but still). We could try to imitate the default style, but I am not sure it is worth.
So how do you do when working with designers that just use a default button from the material android patterns and expect to have the exact size?
You consider size with margins? You create a background style? You try to imitate as much as you can the default button? others?
and this is the simple code used
<Button
android:layout_width="50dp"
android:layout_height="50dp"
/>
<Button
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#drawable/my_button_shape"/>
tha parameter margin is deferent then hight and width. margin determines the distance from point A to the button.
to et the height and width you can use in your xml file the following code:
example:
<Button
android:id = "#id/myButton"
android:layout_width = "50dp"
android:layout_hight = "50dp"
android:text = "test"
android:layout_marginTop = "100dp"
/>
the margin top 100dp determines that my button is 100dp from the top of my layout but the width and height determines the button size
The problem is 9-patch for the default button already includes a margin, so visually the button looks smaller than expected. Possible solutions include negative margins or duplicating the default 9-patch and removing the margin, but each option has its own drawbacks.
As #egonzal says, it would be interesting to know other developers solutions when facing the problem.
I am currently designing the widget for my app (see attached screenshot). Using a LinearLayout I was able to create the following setup:
Image: weight - 2
Title section: weight - 1
Price section: weight -1
However I would like the title and price section to be of fixed height while the image's height changes (shrink or grow) when the user resizes the widget.
How can I make the height of the image dynamic without using layout_weight? Thank you
To achieve a resizable image section all I had to do was change the weight of the Image to 1 and set the actual height in dp for the title and price section.
UPDATE
A more efficient alternative is to use RealtiveLayout, this can be achieved by:
1. Having the price section having fixed height and aligned to parent bottom
2. Set the title section having fixed size and above the price
3. Set the image as match_parent height and above the title.
I set the button's height via XML. Suppose it to be X
<Button
android:layout_height="wrap_contnet"
android:textSize = " <X> dp"
....
....
/>
If I set X to greater than 15 dp, the button's height grows to fit the text. But when I set it to something lower like 2dp, the button's height doesn't change and I can see a thick border around it as shown below:-
As shown above, text size is so small but still height doesn't decrease!
How can I force it to be of appropriate height?
Thanx in advance!
Font size does not depend on button height. If you set it too small to fit the text, you will get the result you observe
EDIT
wrap_content would usually do the trick, however Button class sets some layout parameters like margin, background so it takes more space. You may get rid of Button and use i.e. TextView class, styled by hand to match your design. onClickListener will work perfectly fine with it and you will get result you want and full control over your button
EDIT 2
As this is bit related - there's AutoFitTextView widget on Github that deals with automatic text size scalling: https://github.com/grantland/android-autofittextview
Just Set android:minHeight="xxdp"