TextView 자동 크기 조절
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
Android 8.0 (API 수준 26) 이상에서는
TextView
- 텍스트 크기 허용
자동으로 확장 또는 축소하여
TextView
의 특성 및 경계 이 설정을 사용하면
동적 콘텐츠를 사용하여 다양한 화면에서 텍스트 크기를 최적화합니다.
지원 라이브러리 26.0은 TextView
자동 크기 조절을 완벽하게 지원합니다.
기능을 사용하지 않습니다.
android.support.v4.widget
패키지에는 TextViewCompat
가 포함되어 있습니다.
클래스를 사용하여 이전 버전과 호환되는 방식으로 특성에 액세스할 수 있습니다.
TextView 자동 크기 조절 설정
프레임워크 또는 지원 라이브러리를 사용하여
프로그래매틱 방식으로 또는 XML에서 TextView
를 사용합니다. XML 속성을 설정하기 위해 Android 스튜디오에서 Properties 창을 사용할 수도 있습니다.
TextView
자동 크기 조절을 설정하는 방법에는 세 가지가 있습니다.
다음 섹션에 설명되어 있습니다.
참고: XML 파일에 자동 크기 조절을 설정하면
'wrap_content' 값을 사용하여 추천됨 대상
다음의 layout_width
또는 layout_height
속성
TextView
입니다. 이렇게 하면
예기치 않은 결과를 얻을 수 있습니다.
기본
기본 설정을 사용하면 TextView
크기 자동 크기 조절이 허용됩니다.
가로축 및 세로축에서 균일하게 사용됩니다.
- 기본 설정을 프로그래매틱 방식으로 정의하려면
<ph type="x-smartling-placeholder"></ph>
setAutoSizeTextTypeWithDefaults(int autoSizeTextType)
메서드를 사용하여 지도 가장자리에
패딩을 추가할 수 있습니다. 사용 중지하려면 AUTO_SIZE_TEXT_TYPE_NONE
를 입력하세요.
자동 크기 조절 기능 또는 AUTO_SIZE_TEXT_TYPE_UNIFORM
를
가로축과 세로축의 크기를 균일하게 조정합니다.
참고: 균일한 크기 조정의 기본 크기는 minTextSize = 12sp
, maxTextSize = 112sp
및 granularity = 1px.
입니다.
- XML에서 기본 설정을 정의하려면
android
네임스페이스를 사용합니다.
그런 다음
autoSizeTextType
속성을 없음으로 설정하거나
uniform).
<?xml version="1.0" encoding="utf-8"?>
<TextView
android:layout_width="match_parent"
android:layout_height="200dp"
android:autoSizeTextType="uniform" />
지원 라이브러리를 사용하여 기본 설정 정의
세부사항
최소 및 최대 텍스트 크기 범위와 각 단계의 크기를 지정하는 치수를 정의할 수 있습니다. TextView
는 최소 및 최대 크기 속성 사이의 범위에서 균일하게 조정됩니다. 각 증분은
세분성 속성에 설정된 크기입니다.
지원 라이브러리를 사용하여 세부사항 정의
미리 설정된 크기
미리 설정된 크기를 사용하면
TextView
에서 텍스트 자동 크기 조절 시 선택합니다.
-
미리 설정된 크기를 사용하여 프로그래매틱 방식으로
TextView
자동 크기 조절을 설정하려면 setAutoSizeTextTypeUniformWithPresetSizes(int[] presetSizes, int unit)
메서드를 호출하세요. 크기 배열 및 크기의 TypedValue
치수 단위를 지정합니다.
- 미리 설정된 크기를 사용하여 XML에서
TextView
자동 크기 조절을 설정하려면 android
네임스페이스를 사용하고 다음 속성을 설정하세요.
autoSizeTextType
설정
속성을 none 또는 uniform으로 설정합니다. 없음
기본값이며 uniform으로 설정하면
TextView
배율이 가로 및 세로에서 균일하게
표시됩니다.
autoSizePresetSizes
속성을 미리 설정된 크기의 배열로 설정합니다. 리소스인 배열에 액세스하려면 res/values/arrays.xml
파일에서 배열을 정의하세요.
<resources>
<array name="autosize_text_sizes">
<item>10sp</item>
<item>12sp</item>
<item>20sp</item>
<item>40sp</item>
<item>100sp</item>
</array>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<TextView
android:layout_width="match_parent"
android:layout_height="200dp"
android:autoSizeTextType="uniform"
android:autoSizePresetSizes="@array/autosize_text_sizes" />
지원 라이브러리를 사용하여 미리 설정된 크기 설정
- 미리 설정된 크기를 사용하여
TextView
프로그래매틱
지원 라이브러리를 통해
<ph type="x-smartling-placeholder"></ph>
TextViewCompat.setAutoSizeTextTypeUniformWithPresetSizes(TextView textView, int[] presetSizes, int unit)
메서드를 사용하여 축소하도록 요청합니다. TextView
클래스의 인스턴스,
크기 배열 및 모든 TypedValue
치수 단위
지정할 수 있습니다.
- 미리 설정된 크기를 사용하여
TextView
을 XML로 변환하려면
app
네임스페이스를 설정하고 autoSizeTextType
및
레이아웃 XML 파일의 autoSizePresetSizes
속성.
<resources>
<array name="autosize_text_sizes">
<item>10sp</item>
<item>12sp</item>
<item>20sp</item>
<item>40sp</item>
<item>100sp</item>
</array>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="200dp"
app:autoSizeTextType="uniform"
app:autoSizePresetSizes="@array/autosize_text_sizes" />
</LinearLayout>
추가 리소스
동적 소재 사용 시 TextView
자동 크기 조절에 관한 추가 정보
콘텐츠, 시청
Android Jetpack: TextView 자동 크기 조절
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-07-26(UTC)
[null,null,["최종 업데이트: 2025-07-26(UTC)"],[],[],null,["# Autosize TextViews\n\nWith Android 8.0 (API level 26) and higher, you can instruct a\n[TextView](/reference/android/widget/TextView) to let the text size\nexpand or contract automatically to fill its layout based on the\n`TextView`'s characteristics and boundaries. This setting makes it easier to\noptimize text size on different screens with dynamic content.\n\n\nSupport Library 26.0 fully supports the autosizing `TextView`\nfeature on devices running Android versions 8.0 (API level 26) or lower.\nThe `android.support.v4.widget` package contains the `TextViewCompat`\nclass to access features in a backward-compatible fashion.\n\nSet up TextView autosize\n------------------------\n\n\nYou can either use the framework or Support Library to set up the autosizing of\n`TextView` programmatically or in XML. To\nset the XML attributes, you can also use the **Properties**\nwindow in Android Studio.\n\n\nThere are three ways you can set up the autosizing of `TextView`,\ndescribed in the sections that follow:\n\n- [Default](#default)\n- [Granularity](#granularity)\n- [Preset sizes](#preset-sizes)\n\n**Note** : If you set autosizing in an XML file, we do not\nrecommended using the value \"wrap_content\" for the\n`layout_width` or `layout_height` attributes of a\n`TextView`. Doing so might produce\nunexpected results.\n\n### Default\n\n\nThe default setting lets the autosizing of `TextView` scale\nuniformly on horizontal and vertical axes.\n\n- To define the default setting programmatically, call the [`setAutoSizeTextTypeWithDefaults(int autoSizeTextType)\n `](/reference/android/widget/TextView#setAutoSizeTextTypeWithDefaults(int)) method. Provide `AUTO_SIZE_TEXT_TYPE_NONE` to turn off the autosizing feature or `AUTO_SIZE_TEXT_TYPE_UNIFORM` to scale the horizontal and the vertical axes uniformly.\n- **Note** : The default dimensions for uniform scaling are `minTextSize = 12sp`, `maxTextSize = 112sp`, and `granularity = 1px.`\n- To define the default setting in XML, use the `android` namespace and set the [`autoSizeTextType`](/reference/android/widget/TextView#attr_android:autoSizeTextType) attribute to *none* or *uniform*. \n\n```xml\n\u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n\u003cTextView\n android:layout_width=\"match_parent\"\n android:layout_height=\"200dp\"\n android:autoSizeTextType=\"uniform\" /\u003e\n```\n\n#### Define the default setting using the Support Library\n\n- To define the default setting programmatically through the Support Library, call the [`TextViewCompat.setAutoSizeTextTypeWithDefaults(TextView textview, int autoSizeTextType)`](/reference/androidx/core/widget/TextViewCompat#setAutoSizeTextTypeWithDefaults(android.widget.TextView,int)) method. Provide an instance of the `TextView` widget and one of the text types, such as `TextViewCompat.AUTO_SIZE_TEXT_TYPE_NONE` or `TextViewCompat.AUTO_SIZE_TEXT_TYPE_UNIFORM`.\n- To define the default setting in XML through the Support Library, use the `app` namespace and set the `autoSizeTextType` attribute to *none* or *uniform*. \n\n```xml\n\u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n\u003cLinearLayout\n xmlns:android=\"http://schemas.android.com/apk/res/android\"\n xmlns:app=\"http://schemas.android.com/apk/res-auto\"\n android:layout_width=\"match_parent\"\n android:layout_height=\"match_parent\"\u003e\n\n \u003cTextView\n android:layout_width=\"match_parent\"\n android:layout_height=\"200dp\"\n app:autoSizeTextType=\"uniform\" /\u003e\n\n\u003c/LinearLayout\u003e\n```\n\n### Granularity\n\n\nYou can define a range of minimum and maximum text sizes and a\ndimension that specifies the size of each step. The\n`TextView` scales uniformly in a range between the\nminimum and maximum size attributes. Each increment occurs as the step\nsize set in the granularity attribute.\n\n- To define a range of text sizes and a dimension programmatically, call the [setAutoSizeTextTypeUniformWithConfiguration(int autoSizeMinTextSize, int autoSizeMaxTextSize, int autoSizeStepGranularity, int unit)](/reference/android/widget/TextView#setAutoSizeTextTypeUniformWithConfiguration(int, int, int, int)) method. Provide the maximum value, the minimum value, the granularity value, and any [TypedValue](/reference/android/util/TypedValue) dimension unit.\n- To define a range of text sizes and a dimension in XML, use the `android` namespace and set the following attributes:\n - Set the `autoSizeTextType` attribute to either *none* or *uniform* . The *none* value is the default, and *uniform* lets `TextView` scale uniformly on horizontal and vertical axes.\n- Set the [`autoSizeMinTextSize`](/reference/android/widget/TextView#attr_android:autoSizeMinTextSize), [`autoSizeMaxTextSize`](/reference/android/widget/TextView#attr_android:autoSizeMaxTextSize), and [`autoSizeStepGranularity`](/reference/android/widget/TextView#attr_android:autoSizeStepGranularity) attributes to define the dimensions for the autosizing of `TextView`. \n\n```xml\n\u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n\u003cTextView\n android:layout_width=\"match_parent\"\n android:layout_height=\"200dp\"\n android:autoSizeTextType=\"uniform\"\n android:autoSizeMinTextSize=\"12sp\"\n android:autoSizeMaxTextSize=\"100sp\"\n android:autoSizeStepGranularity=\"2sp\" /\u003e\n```\n\n#### Define granularity using the Support Library\n\n- To define a range of text sizes and a dimension programmatically through the Support Library, call the [`TextViewCompat.setAutoSizeTextTypeUniformWithConfiguration(int autoSizeMinTextSize, int autoSizeMaxTextSize, int autoSizeStepGranularity, int unit)`](/reference/androidx/core/widget/TextViewCompat#setAutoSizeTextTypeUniformWithConfiguration(android.widget.TextView,int,int,int,int)) method. Provide the maximum value, the minimum value, the granularity value, and any `TypedValue` dimension unit.\n- To define a range of text sizes and a dimension in XML through the Support Library, use the `app` namespace and set the `autoSizeText`, `autoSizeMinTextSize`, `autoSizeMaxTextSize`, and `autoSizeStepGranularity` attributes in the layout XML file. \n\n```xml\n\u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n\u003cLinearLayout\n xmlns:android=\"http://schemas.android.com/apk/res/android\"\n xmlns:app=\"http://schemas.android.com/apk/res-auto\"\n android:layout_width=\"match_parent\"\n android:layout_height=\"match_parent\"\u003e\n\n \u003cTextView\n android:layout_width=\"match_parent\"\n android:layout_height=\"200dp\"\n app:autoSizeTextType=\"uniform\"\n app:autoSizeMinTextSize=\"12sp\"\n app:autoSizeMaxTextSize=\"100sp\"\n app:autoSizeStepGranularity=\"2sp\" /\u003e\n\n\u003c/LinearLayout\u003e\n```\n\n### Preset sizes\n\n\nPreset sizes let you specify the values that the\n`TextView` picks when autosizing text.\n\n- To use preset sizes to set up the autosizing of `TextView` programmatically, call the [setAutoSizeTextTypeUniformWithPresetSizes(int[] presetSizes, int unit)](/reference/android/widget/TextView#setAutoSizeTextTypeUniformWithPresetSizes(int[], int)) method. Provide an array of sizes and any `TypedValue` dimension unit for the size.\n- To use preset sizes to set up the autosizing of `TextView` in XML, use the `android` namespace and set the following attributes:\n - Set the `autoSizeTextType` attribute to either *none* or *uniform* . The *none* value is the default, and *uniform* lets `TextView` scale uniformly on horizontal and vertical axes.\n- Set the [`autoSizePresetSizes`](/reference/android/widget/TextView#attr_android:autoSizePresetSizes) attribute to an array of preset sizes. To access the array as a resource, define the array in the `res/values/arrays.xml` file. \n\n```xml\n\u003cresources\u003e\n \u003carray name=\"autosize_text_sizes\"\u003e\n \u003citem\u003e10sp\u003c/item\u003e\n \u003citem\u003e12sp\u003c/item\u003e\n \u003citem\u003e20sp\u003c/item\u003e\n \u003citem\u003e40sp\u003c/item\u003e\n \u003citem\u003e100sp\u003c/item\u003e\n \u003c/array\u003e\n\u003c/resources\u003e\n``` \n\n```xml\n\u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n\u003cTextView\n android:layout_width=\"match_parent\"\n android:layout_height=\"200dp\"\n android:autoSizeTextType=\"uniform\"\n android:autoSizePresetSizes=\"@array/autosize_text_sizes\" /\u003e\n```\n\n#### Set up preset sizes using the Support Library\n\n- To use preset sizes to set up the autosizing of `TextView` programmatically through the Support Library, call the [`TextViewCompat.setAutoSizeTextTypeUniformWithPresetSizes(TextView textView, int[] presetSizes, int unit)`](/reference/androidx/core/widget/TextViewCompat#setAutoSizeTextTypeUniformWithPresetSizes(android.widget.TextView,int[],int)) method. Provide an instance of the `TextView` class, an array of sizes, and any `TypedValue` dimension unit for the size.\n- To use preset sizes to set up the autosizing of `TextView` in XML through the Support Library, use the `app` namespace and set the `autoSizeTextType` and `autoSizePresetSizes` attributes in the layout XML file. \n\n```xml\n\u003cresources\u003e\n \u003carray name=\"autosize_text_sizes\"\u003e\n \u003citem\u003e10sp\u003c/item\u003e\n \u003citem\u003e12sp\u003c/item\u003e\n \u003citem\u003e20sp\u003c/item\u003e\n \u003citem\u003e40sp\u003c/item\u003e\n \u003citem\u003e100sp\u003c/item\u003e\n \u003c/array\u003e\n\u003c/resources\u003e\n``` \n\n```xml\n\u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n\u003cLinearLayout\n xmlns:android=\"http://schemas.android.com/apk/res/android\"\n xmlns:app=\"http://schemas.android.com/apk/res-auto\"\n android:layout_width=\"match_parent\"\n android:layout_height=\"match_parent\"\u003e\n\n \u003cTextView\n android:layout_width=\"match_parent\"\n android:layout_height=\"200dp\"\n app:autoSizeTextType=\"uniform\"\n app:autoSizePresetSizes=\"@array/autosize_text_sizes\" /\u003e\n\u003c/LinearLayout\u003e\n```\n\nAdditional resources\n--------------------\n\n\nFor additional information on autosizing a `TextView` when working with dynamic\ncontent, watch\n[Android Jetpack: Autosizing TextView](https://www.youtube.com/watch?v=JYrpEAz_A1U)."]]