I have such textview in my layout:
<com.google.android.material.textview.MaterialTextView
android:id="@ id/text_body"
style="@style/TvFontSize"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="10dp"
android:justificationMode="inter_word"
android:textColor="@color/gray_color"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/text_header" />
with such style:
<style name="TvFontSize">
<item name="android:autoSizeMaxTextSize">100sp</item>
<item name="android:autoSizeMinTextSize">16sp</item>
<item name="android:autoSizeStepGranularity">2sp</item>
<item name="android:autoSizeTextType">uniform</item>
</style>
and long text is cut off as can see:
full layout is below:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:overScrollMode="never"
android:scrollbars="none">
<androidx.constraintlayout.widget.ConstraintLayout xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/bottom_nav_color"
tools:context=".pollsModule.IntroFinalFragment">
<com.google.android.material.appbar.AppBarLayout
android:id="@ id/toolbarContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.appcompat.widget.Toolbar
android:id="@ id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:subtitleTextAppearance="@style/Toolbar.SubtitleText"
app:titleTextAppearance="@style/Toolbar.TitleText">
<TextView
android:id="@ id/polls_title"
style="@android:style/TextAppearance.Holo.Widget.ActionBar.Title.Inverse"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="2"
android:textAlignment="center" />
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
<View
android:id="@ id/divider"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_marginTop="3dp"
android:background="@color/polls_color"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/toolbarContainer" />
<com.google.android.material.textview.MaterialTextView
android:id="@ id/text_header"
style="@style/TvFontSize"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_margin="10dp"
android:textAlignment="center"
android:textColor="@color/gray_color"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/divider" />
<com.google.android.material.textview.MaterialTextView
android:id="@ id/text_body"
style="@style/TvFontSize"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="10dp"
android:inputType="textMultiLine"
android:justificationMode="inter_word"
android:singleLine="false"
android:text="dfjjnfdjnfdjndfjnfdjfjdnjnfdjndfdfjfdjnfnjddfjjnfdjnfdjndfjnfdjfjdnjnfdjndfdfjfdjnfnjddfjjnfdjnfdjndfjnfdjfjdnjnfdjndfdfjfdjnfnjddfjjnfdjnfdjndfjnfdjfjdnjnfdjndfdfjfdjnfnjddfjjnfdjnfdjndfjnfdjfjdnjnfdjndfdfjfdjnfnjddfjjnfdjnfdjndfjnfdjfjdnjnfdjndfdfjfdjnfnjddfjjnfdjnfdjndfjnfdjfjdnjnfdjndfdfjfdjnfnjddfjjnfdjnfdjndfjnfdjfjdnjnfdjndfdfjfdjnfnjddfjjnfdjnfdjndfjnfdjfjdnjnfdjndfdfjfdjnfnjddfjjnfdjnfdjndfjnfdjfjdnjnfdjndfdfjfdjnfnjd"
android:textColor="@color/gray_color"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/text_header" />
<com.google.android.material.button.MaterialButton
android:id="@ id/next_text"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_margin="10dp"
android:layout_marginTop="10dp"
android:maxLines="1"
android:textAllCaps="false"
android:textColor="@color/white"
app:autoSizeMaxTextSize="16sp"
app:autoSizeMinTextSize="6sp"
app:autoSizeStepGranularity="2sp"
app:autoSizeTextType="uniform"
app:backgroundTint="@color/colorAccent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@ id/text_body" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
</layout>
I can't imagine how to fix it. I tried to use:
android:inputType="textMultiLine"
android:singleLine="false"
but it didn't help me :(
CodePudding user response:
This attribute affects your TextView
. Just remove this attribute from your style
part.
<item name="android:autoSizeTextType">uniform</item>
For enabling autoSizeTextType
. You have to make your textView
height Hardcore means in fixed size like android:layout_height="300dp"
or match parent
.
I hope it helps.
Thank you @Andrew for your clarification.
CodePudding user response:
your TextView
should probably have height set to wrap_content
instead of 0dp
...
android:layout_height="wrap_content"