DEV Community

Laszlo Toth
Laszlo Toth

Posted on

Autosizing TextViews in Android Studio

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

Top comments (2)

Collapse
 
s_aitchison profile image
Suzanne Aitchison

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 πŸ™‚

Collapse
 
trackrunner profile image
Laszlo Toth • Edited

Hi,

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

GitHub logo LaszloLajosT / Udacity-Project-Athletic_Club

1. Project: Single Screen App from Udacity.

Athletic_Club

Single Screen Project.

Project Overview

Design and implement a single screen app that displays information about a fictional small business. Think along the lines of your favorite coffeeshop, local restaurant, or that gem of a store that sells those rare comic books or records.

Suggested App Ideas

Details about a small business in your neighborhood Contact info and description about your workplace or school Info about a special interest group (like a club or sports team) you’re part of and how new members can sign up

Requirements

Your design must include:

  • Business name

  • At least one photo representing the business

  • Two or more other pieces of information, such as:

    ~ Contact information for the business (eg phone number, email address, website)

    ~ Address of the Business

    ~ Description of business

    ~ Hours of operation






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?