Autosizing TextViews in Android Studio

github logo ・1 min read

Hi everyone,

I created an Android app ( a single screen app with information of athletic club). I used a ScrollView and inside it a RelativeLayout with some TextViews/Imageviews. I would like to change all the TextView's size depends from device size.

I read articles about Autosizing like this.

Update:
My question is:
Can I use autozising TextViews in RelativeLayout and keep all my positioning in same time? Unfortunately, when I use any kind of code for autosizing then my TextViews move from right to left. Or I am on a wrong path and I need to rethink it?

Any advice I would really appreciate.
Thank you

twitter logo DISCUSS (2)
markdown guide
 

I think you should be able to use them in whatever layout... Do you have a repo you can share? Would be easier to help debug if we can have a look at it 🙂

 

Hi,

I just realised I used a wrong code in my xml file.
Here is my app without any autosizing.

GitHub logo LaszloLajosT / BAC

Single Screen Project.

Single Screen App

Basically, it's a single screen app which shows contact information about an athletic club. (Like a business card.)




When I change the first TextView's code to this:

<TextView
            android:id="@+id/cityname"
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:autoSizeTextType="uniform"
            android:autoSizeMinTextSize="36sp"
            android:autoSizeMaxTextSize="100sp"
            android:autoSizeStepGranularity="2sp"

            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:paddingLeft="16dp"
            android:paddingTop="20dp"
            android:paddingRight="16dp"
            android:paddingBottom="8dp"
            android:text="Bournemouth"
            android:textColor="@android:color/white" /> 

then the TextView's positioning is not working anymore. That's why I thought maybe I can't use autosizing inside RelativeLayout?

Classic DEV Post from Nov 14

Share your CSS knowledge

Laszlo Toth profile image
I started to learn basics on Android in Udacity(25/10/2019). This is my first proper code contact after I quit from University(2015).