Dec 17 | 7:25 PM |
Mark M. | has entered the room |
Mark M. | turned on guest access |
Dec 17 | 7:30 PM |
J | has entered the room |
Mark M. |
hello, J!
|
Mark M. |
how can I help you today?
|
J |
i would like to ask about design methods in dealing with different screen sizes
|
Dec 17 | 7:35 PM |
Mark M. |
can you be more specific?
|
J |
for example how to make a button, image or text to be of similar size across all screen sizes
|
Mark M. |
size it using dimensions measured in dp (e.g., 48dp)
|
Mark M. |
48dp is the same size across all screen sizes
|
Mark M. |
now, that may be a problem when you want to put a larger widget in a smaller device screen
|
Mark M. |
so, usually, "of similar size across all screen sizes" is something to be done on occasion, not all the time
|
J |
if thats the case how to make the components to scale size according to different screen sizes
|
Mark M. |
there are options with ConstraintLayout for that, such as sizing things based on a percentage of the screen width or height
|
J |
for now im using guidelines in constraintlayout to resize buttons in percentage, however im not sure if theres a better way
|
Mark M. |
that works
|
Dec 17 | 7:40 PM |
J |
cause i will need alot of guidelines if i were to resize every single components
|
Mark M. |
there are also app:layout_constraintWidth_percent and app:layout_constraintHeight_percent
|
Mark M. |
those are good if an individual widget, in isolation, needs to be sized based on screen dimensions
|
J |
which is more preferable in what case scenario
|
Mark M. |
guidelines are better for positioning, where you need to position based on screen size (percentage) instead of positioning relative to another widget directly
|
Mark M. |
guidelines are also good for having multiple widgets all tie to a particular spot
|
J |
so guidelines are more independent than another?
|
Mark M. |
I do not know how to answer that, sorry
|
Mark M. |
if you just want a widget to size as a percentage of the screen ("make this button be 25% by 25% of the screen), I would use app:layout_constraintWidth_percent and app:layout_constraintHeight_percent
|
Mark M. |
note that you can also use app:layout_constraintWidth_min and app:layout_constraintHeight_min to set lower bounds, so the widget does not get too small
|
Mark M. |
and app:layout_constraintWidth_max and app:layout_constraintHeight_max to set upper bounds, so the widget does not get too large
|
Dec 17 | 7:45 PM |
Mark M. |
these sorts of rules are fine for small changes in window size, such as from one phone to another phone
|
J |
may i assume that guidelines = constraintwidth_percent and bias?
|
Mark M. |
I would not describe them that way
|
Mark M. |
going back to your earlier question, guidelines are independent things, that happen to be positioned on a percentage basis
|
Mark M. |
so, guidelines can offer things that you cannot get purely with widget attributes, such as "have this button's top edge be 35% of the way down the screen from the top"
|
Mark M. |
guidelines *can* be used for sizing, but their strength is more in positioning, IMHO
|
Mark M. |
and, FWIW, for larger changes, such as supporting tablets or resizeable Chrome OS windows, you may need to consider using separate layout resources in appropriate resource sets (e.g., res/layout-w800dp/)
|
J |
would having too much guidelines affect the app performance?
|
Mark M. |
I do not know
|
Mark M. |
they are not views, so they do not take time on their own when rendering the UI
|
Mark M. |
I do not know if guideline-based calculations that ConstraintLayout does are slow, compared to other calculations
|
J |
i see, i will stick to guidelines for now then
|
J |
im trying to design my app being responsive to different screen sizes
|
Dec 17 | 7:50 PM |
Mark M. |
that is a fine objective
|
J |
is there a way to make the image within button to scale accordingly as well?
|
Mark M. |
if you are using ImageButton, that should happen automatically
|
Mark M. |
if you are running into problems, look into the android:scaleType attribute
|
J |
cause right now i had only resize the image to be smaller but i would prefer to get it resize automatically
|
J |
i would be having both text and image within the button so im not sure if imagebutton able to do it
|
Mark M. |
if you are using drawableStart and drawableEnd, I am uncertain how to scale them, sorry
|
J |
would it be possible to use different image sizes for different screen then
|
Mark M. |
you could use different drawable resources based on screen size
|
Dec 17 | 7:55 PM |
Mark M. |
on the whole, I try to avoid drawableStart and drawableEnd
|
Mark M. |
if I wanted a button-like thing that had image and text, I would wrap a TextView and an ImageView in a container (ConstraintLayout or whatever)
|
Mark M. |
and put a background on the container that had the states for pressed, etc.
|
Mark M. |
or, find an existing widget that handled that sort of pattern
|
J |
how much nested layouts is too much in general
|
J |
i have searched before that nested layouts could be slowing down the app
|
Mark M. |
that is really only a performance problem in a scrolling container
|
Mark M. |
so, in a RecyclerView for a vertical list, having highly complex rows may slow down the app
|
J |
as the app im developing is for massive number of users so im quite concerned with its performance
|
Mark M. |
ConstraintLayout exists to avoid that sort of nesting in many cases
|
Dec 17 | 8:00 PM |
J |
so the performance is only affected on that particular container instead of the whole app?
|
Mark M. |
yes
|
Mark M. |
if you have four activities, the UI rendering speed of Activity A do not affect Activity B, C, or D
|
Mark M. |
if you are using ConstraintLayout, it is unlikely that for an individual layout resource you will wind up with too many nested containers
|
J |
i see
|
Dec 17 | 8:05 PM |
J |
what about text within a component like textview or button? if the content is too long within the constraint, remaining text will appear in new line which might affect the position of other components. is there a way to avoid that and keeping those text within its own space?
|
Mark M. |
TextView offers auto-sizing, where the font scales as needed
|
Mark M. |
you would use stuff like android:maxLines to limit the number of lines of text
|
Mark M. |
then let the auto-sizing take over from there
|
Mark M. | |
Mark M. |
if you are using AppCompatActivity, use app: instead of android: for the attributes, if your minSdkVersion is below 26
|
J |
only textview able to auto scale font size?
|
Mark M. |
and anything that extends from TextView, such as Button
|
Dec 17 | 8:10 PM |
J |
okay then i will have a try on it
|
J |
next i would like to ask about what database is better for massive number of users
|
Mark M. |
you only have one user of an Android device, usually
|
J |
i read from your book about sqlite but from what i searched its more of a local database
|
Mark M. |
and I'm not an expert on server database sizing
|
J |
im looking for database which can be accessed by every user together
|
Mark M. |
I will be honest: you need to scale back your expectations
|
Mark M. |
a "massive number of users" will require a substantial investment in money, time, and talent
|
Mark M. |
it will be far more important for you to be able to start small and grow, choosing appropriate technologies for different phases of that growth
|
J |
which database is good as start up for multiple user access then
|
J |
i cant use sqlite as the database is stored locally within their own devices
|
Mark M. |
sorry, but I do not provide advice for what to use on a server, in terms of that kind of specific technology
|
Mark M. |
SQLite can work on servers
|
Mark M. |
you used it to get to this chat, for example, as the Warescription site stores its data in SQLite
|
Mark M. |
and, for a small user base, my technology choices are reasonable
|
Dec 17 | 8:15 PM |
Mark M. |
but I do not make recommendations on that, as my choices are unusual
|
J |
is there an open source database similar to firebase then
|
Mark M. |
sorry, but I have not researched that recently
|
Mark M. |
I help organizations that have server teams in place that handle that sort of stuff
|
J |
the app which im trying to develop now is more of a online shopping app
|
J |
thats why im looking for such database
|
J |
if you are unsure of it alright then
|
Dec 17 | 8:20 PM |
J |
thats all i have to ask for now, thanks alot
|
Mark M. |
you're welcome!
|
Dec 17 | 8:30 PM |
Mark M. |
that
|
Mark M. |
er, that's a wrap for today's chat
|
Mark M. |
the transcript will be published on https://commonsware.com/office-hours/ shortly
|
Mark M. |
the next chat is Thursday at 8:30am US Eastern
|
Mark M. |
have a pleasant day!
|
J | has left the room |
Mark M. | turned off guest access |