Office Hours — Today, May 5

Saturday, May 2

May 5
8:25 AM
Mark M.
has entered the room
Mark M.
turned on guest access
9:05 AM
sudokai
has entered the room
9:10 AM
Mark M.
hello, sudokai!
sudokai
Hi Mark
Mark M.
how can I help you today?
sudokai
Do you know any way I can crop the top or bottom of an image?
ImageView only has the "centerCrop" option
Mark M.
off the top of my head, I don't, unless the image is a Bitmap
for a Bitmap, you can always transform it using a Matrix or something
sudokai
Android UI is pretty hard. I just spend the entire morning trying to apply border radius to a ImageView on one side of the image only
Mark M.
I'd phrase it more as "easy things in Android UI are not too bad, but there are only so many easy things in Android UI" :-)
sudokai
I ended up doing this and it seems to work
View paste (8 more lines)
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="@android:color/white" />
            <corners android:radius="10dp" />
        </shape>
    </item>
    <item
        android:bottom="10dp"
        android:right="10dp">
        <shape android:shape="rectangle">
            <solid android:color="@android:color/white" />
        </shape>
    </item>
...
9:15 AM
Mark M.
it has a been a long time since I used attributes like android:bottom="10dp" (assuming that I ever have...)
sudokai
Then setting this as the imageview background and enabling clipToOutline
Mark M.
other than the lack of RTL support, though, what you have there seems reasonable
sudokai
Of course, there's a bug since who knows when, and clipToOutline cannot be used in xml because of that, so you need to do it in Kotlin/Java
I guess I'm just venting...
Mark M.
yeah, I feel like pointing out that none of this is my fault, AFAIK :-)
sudokai
How come everything is so badly designed?
Like the 3 classes for Fragment, this sort of stuff...
Mark M.
partly, I'd phrase it more as "organically designed", as there has been a lot of cruft from 12+ years of development
partly, thanks to backwards compatibility concerns, some early hardware limitations continue to limit our framework APIs, even when the hardware itself is better
so, for example, the three fragments are a bit of both of those things
9:20 AM
Mark M.
fragments didn't exist in API Level 1 and were introduced in API Level 11, so they weren't designed into the framework at the outset
sudokai
View paste
> for a Bitmap, you can always transform it using a Matrix or something

Does that work with vector drawables then?
Mark M.
no, unless you render that vector to a Bitmap first
sudokai
About about the shape xml I showed before, it took me a lot of googling to find it but I still don't fully understand it
There's <corners android:radius="10dp" /> to get rounded corners on 4 sides
That part is clear
But then
View paste
<item
        android:bottom="10dp"
        android:right="10dp">
Actually turns the top left rounded corner into a square
View paste
Same with <item
        android:bottom="10dp"
        android:left="10dp">
It turns the top right corner into a square one
Mark M.
it's more that you are defining three layers (<layer-list>)
later items in the XML are higher on the Z axis
and you don't have <corners android:radius="10dp" /> on those latter two items
9:25 AM
Mark M.
so they will be square, and since they are higher on the Z axis, they will overlap your rounded corners from the bottom layer
sudokai
Yeah, that part I understood, it's like putting layers on top
My question is really how android:bottom works?
Mark M.
like I said, if I have ever used that, it's been years and years
so, off the top of my head, I can't answer that, sorry
sudokai
I've just been playing with it, I think I finally undrstand
It's like CSS and position: absolute
You place the layer on top as you said and just move it enough to uncover the rounded corners below
Mark M.
OK
sudokai
That's why bottom right actually covers top left
Mark M.
ah, I see
9:30 AM
Mark M.
anyway, that's a wrap for today's chat
sudokai
Thanks!
Mark M.
the next one is Thursday at 7:30pm US Eastern
sudokai
See you around
Mark M.
have a pleasant day, and stay healthy!
sudokai
has left the room
Mark M.
turned off guest access

Saturday, May 2

 

Office Hours

People in this transcript

  • Mark Murphy
  • sudokai