Office Hours — Today, February 2

Wednesday, January 30

Feb 2
3:50 PM
Mark M.
has entered the room
Mark M.
turned on guest access
3:55 PM
Gabriele
has entered the room
Gabriele
hello
Mark M.
hello, Gabriele!
how can I help you today?
Gabriele
how are you?
Mark M.
OK, and you?
4:00 PM
Gabriele
I'm fine, too, thanks
I have this ImageButton, but I can't resize it! I'd like to have it bigger, so I set width/height, I've also tried with minWidth/Height
View paste
<ImageButton
        android:id="@+id/Media"
        app:srcCompat="@drawable/ic_play_circle_outline_black_24dp"
        android:background="@null"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:minHeight="96dp"
        android:minWidth="96dp"
        android:layout_below="@id/Nickname"
        android:visibility="invisible"
        android:contentDescription="@string/play_button"
        android:onClick="onMediaClick"/>
View paste
<vector android:autoMirrored="true" android:height="96dp"
    android:tint="#FF9E00" android:viewportHeight="96.0"
    android:viewportWidth="96.0" android:width="96dp" xmlns:android="http://schemas.android.com/apk/res/android">
    <path android:fillColor="#FF000000" android:pathData="M10,16.5l6,-4.5 -6,-4.5v9zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8 8,3.59 8,8 -3.59,8 -8,8z"/>
</vector>
I change its size,but nothing happens
Mark M.
so if you set android:layout_width="200dp" and android:layout_height="200dp", there is no change?
Gabriele
exactly
Mark M.
OK, what is the ImageButton inside, in terms of a container?
Gabriele
View paste
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:app="http://schemas.android.com/apk/res-auto"
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/ConversationListview"
                android:gravity="top"
                android:descendantFocusability="blocksDescendants"
    >
Mark M.
is your problem the size of the RelativeLayout, then? it is set to match_parent for height and width, so its size is controlled by whatever *it* is in
Gabriele
I see the button with the same size, but its container seems bigger (more whitespace)
Mark M.
try playing with android:scaleType, such as setting it to fitCenter
4:05 PM
Mark M.
or perhaps set it to centerInside (I can never remember the difference between those...)
Gabriele
(I set it to wrap_content, should I change it?)
eheh, ok
ok, with fitCenter something changes (a bit bigger)
Mark M.
you would need layout_width and layout_height set to your desired size as well
Gabriele
so maybe fitCenter scale, while centerInside center it like it is
Mark M.
you might also temporarily remove android:background="@null", so you see the full bounds of the ImageButton
Gabriele
thanks
View paste
<ImageButton
        android:id="@+id/Media"
        app:srcCompat="@drawable/ic_play_circle_outline_black_24dp"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:minHeight="200dp"
        android:minWidth="200dp"
        android:scaleType="fitCenter"
        android:layout_below="@id/Nickname"
        android:visibility="invisible"
        android:contentDescription="@string/play_button"
        android:onClick="onMediaClick"/>
Mark M.
OK, so the problem is that the image is still not scaling right, but your overall button size is (presumably) what you want
Gabriele
yes
Mark M.
so, try android:adjustViewBounds="true", and see whether fitCenter or centerInside does what you want for the scaleType
4:10 PM
Gabriele
yes, thanks
View paste
<ImageButton
        android:id="@+id/Media"
        app:srcCompat="@drawable/ic_play_circle_outline_black_24dp"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:minHeight="200dp"
        android:minWidth="200dp"
        android:scaleType="fitCenter"
        android:adjustViewBounds="true"
        android:layout_below="@id/Nickname"
        android:visibility="invisible"
        android:contentDescription="@string/play_button"
        android:onClick="onMediaClick"/>
Mark M.
did that give you what you wanted?
Gabriele
it's still like that
Mark M.
I guess not
Gabriele
eheh
Mark M.
try android:scaleType="centerInside", then
BTW, with a null background, you might as well just use ImageView
Gabriele
this is centerInside
4:15 PM
Mark M.
at this point, I don't really have any other suggestions, other than to try a plain ImageView and see what you get
Gabriele
now trying with an ImageView
View paste
<ImageView
        android:id="@+id/Media"
        app:srcCompat="@drawable/ic_play_circle_outline_black_24dp"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:layout_below="@id/Nickname"
        android:visibility="invisible"
        android:contentDescription="@string/play_button"
        android:onClick="onMediaClick"/>
Mark M.
you may need android:scaleType there too
BTW, are you sure this image is the one whose XML you posted? that XML has an intrinsic size of 96dp, which should be about half of your button size, but this appears much smaller than that
Gabriele
yes
what if I set it to 200 too?
using scaleType do not change anything with ImageView
4:20 PM
Mark M.
you could try playing with the vector drawable content, I suppose
but I'm running out of ideas
Gabriele
eheh
4:25 PM
Mark M.
is there anything else that I can try to help with?
Gabriele
no, thank you.
4:30 PM
Gabriele
I think the problem was android:viewportHeight vs android:height
I created it again using vector asset with a bigger size, 96dp, it set android:viewportHeight="24.0", but it's working
Mark M.
glad to hear you have it under control!
Gabriele
and I'm still using android:scaleType="centerInside" android:adjustViewBounds="true"
ahah, nice work with your kotlin book (even if I haven't read it yet)
Mark M.
thanks!
5:00 PM
Mark M.
that's a wrap for today's chat
the next chat is Tuesday at 9am US Easter
er, US Eastern
have a pleasant day!
Gabriele
has left the room
Mark M.
turned off guest access

Wednesday, January 30

 

Office Hours

People in this transcript

  • Gabriele
  • Mark Murphy