How to wrap text in textview in Android

前端 未结 18 1052
旧巷少年郎
旧巷少年郎 2020-12-08 18:03

Does any one know how to wrap text in TextView in Android platform. i.e if the text in textview exceed the screen length it should be displayed in the second line.

I

相关标签:
18条回答
  • 2020-12-08 18:28

    OK guys the truth is somewhere in the middle cause you have to see the issue from the parent's view and child's. The solution below works ONLY when spinner mode = dialog regardless of Android version (no problem there.. tested it in VD and DesireS with Android =>2.2) :

    1. .Set you spinner's(the parent) mode like :

      android:spinnerMode="dialog"  
      
    2. Set the textview's(child custom view) properties to :

      android:layout_weight="1"  
      android:ellipsize="none"  
      android:maxLines="100"  
      android:scrollHorizontally="false"
      

    I hope this works for you also.

    0 讨论(0)
  • 2020-12-08 18:34

    Use app:breakStrategy="simple" in AppCompatTextView, it will control over paragraph layout.

    It has three constant values

    • balanced
    • high_quality
    • simple

    Designing in your TextView xml

    <android.support.v7.widget.AppCompatTextView
            android:id="@+id/textquestion"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:scrollHorizontally="false"
            android:text="Your Question Display Hear....Your Question Display Hear....Your Question Display Hear....Your Question Display Hear...."
            android:textColor="@android:color/black"
            android:textSize="20sp"
            android:textStyle="bold"
            app:breakStrategy="simple" />
    

    If your current minimum api level is 23 or more then in Coding

    yourtextview.setBreakStrategy(Layout.BREAK_STRATEGY_SIMPLE);
    

    For more refrence refer this BreakStrategy

    0 讨论(0)
  • 2020-12-08 18:37

    For the case where the TextView is inside a TableLayout, the solution is to set android:shrinkColumns="1" on the TableLayout. (Replace 1 with the column number the TextView you want to wrap is in. (0-indexed))

    AFAICT, no other attributes are needed on the TextView.

    For other cases, see the other answers here.

    FWIW, I had initially gotten it to sort of work with

     <TextView
       android:id="@+id/inventory_text"
       android:layout_width="fill_parent"
       android:layout_weight="1"
       android:width="0dp"
    

    but that resulted in some extra empty space at the bottom of the Dialog it was all in.

    0 讨论(0)
  • 2020-12-08 18:38

    This should fix your problem: android:layout_weight="1".

    0 讨论(0)
  • 2020-12-08 18:38

    You need to add your TextView in a ScrollView with something like this :

    <ScrollView android:id="@+id/SCROLL_VIEW"  
    android:layout_height="150px"   
    android:layout_width="fill_parent">  
    
    <TextView   
       android:id="@+id/TEXT_VIEW"   
       android:layout_height="wrap_content"   
       android:layout_width="wrap_content"   
       android:text="This text view should act as header This text view should act as header This text view should act as header This text view should act as header This text view should act as header This text view should act as header This text view should act as header" />  
     </ScrollView>
    
    0 讨论(0)
  • 2020-12-08 18:40

    All you have to do is to set your textview width.

    android:layout_width="60dp"

    you can change the width to your choice. Just type long sentence to check if it working like this

    android:text="i want to be among world class software engineer"

    0 讨论(0)
提交回复
热议问题