2017-10-07 93 views
0

嗨我在我的android應用程序中使用autosize textview。我的應用程序minSdkVersion是19,所以我正在使用支持庫。Autosize textview不起作用

https://developer.android.com/guide/topics/ui/look-and-feel/autosizing-textview.html

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.app.android.registration.RegistrationActivity" 
    tools:ignore="missingPrefix"> 

    <include 
     android:id="@+id/toolbar_registration_layout" 
     layout="@layout/toolbar" /> 

    <TextView 
     android:id="@+id/textview_registration_title" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:fontFamily="@font/lato_medium" 
     android:padding="8dp" 
     android:text="@string/registration_title" 
     app:autoSizeTextType="uniform" 
     app:layout_constraintTop_toBottomOf="@id/toolbar" /> 


</android.support.constraint.ConstraintLayout> 

enter image description here

有誰知道它爲什麼不調整因爲有很多在它右側的可用空間。

+0

可能無法正常工作,先生,@IntelliJAmiya – UltimateDevil

+1

@UltimateDevil得到了點。您應該添加靜態高度 –

+1

MyPleasure Sir,@IntelliJAmiya :) – UltimateDevil

回答

1

更改android:layout_height="wrap_content"爲特定值

像:android:layout_height="200dp"

您可以在文檔閱讀 - :

注意:如果設置在一個XML文件自動調整大小,它是不建議使用layout_widthlayout_height屬性的值「wrap_content」作爲TextView的屬性。它可能產生意想不到的結果

enter image description here

所以,你必須通過一個固定值android:layout_heightTextView

希望,這將幫助你

+0

但是,傳遞固定高度的textview並不是很好 –

+0

也許,但根據文檔進行自動調整,您必須通過固定高度 – UltimateDevil

+0

@Nancy,this [video](https ://www.youtube.com/watch?v = fjUdJ2aVqE4)可以幫助你理解 – UltimateDevil