0

My question is similar to this

How to stop a GridView from cropping my images?

Iam Using Flowlayout for creating Tag Cloud, I was able to create it, Iam inflating the text view since the text can vary, I have seen all the examples which uses new line has a fixed layout xml. how to implement new line in inflated textview.

Community
  • 1
  • 1
naren
  • 71
  • 2

2 Answers2

0

It appears that the new line flag on the FlowLayout.LayoutParams object is not modifiable at runtime. You will either need to modify the library itself to add this ability or keep a separate layout file for when you need to inflate a TextView with the newline xml.

If you are looking to break the text across two lines and continue to use the FlowLayout, you will need to inflate two separate TextViews one for the first line and one for the second. You will also need to manually calculated the amount of text you can fit on screen to do this.

Bill
  • 413
  • 2
  • 10
0

Parent layout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.example.customns"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
tools:context=".CustomActivity" 
android:orientation="vertical">
<com.example.customns.FlowLayout
    android:id="@+id/loadlayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:orientation="horizontal"
    >
</com.example.customns.FlowLayout>
</RelativeLayout>

Layout to be inflated in the parent

<?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/com.example.customns"
android:id="@+id/buttonContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"  
android:layout_alignParentBottom="true"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"  
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp" 
android:background="@color/blue"
android:orientation="horizontal" >

<TextView    
     app:layout_newLine="true"
    android:id="@+id/text1"
    android:layout_width="wrap_content"       
    android:layout_height="wrap_content" 
     android:layout_marginTop="5dp"
     android:layout_marginBottom="5dp"  
     android:layout_marginLeft="5dp"
     android:layout_marginRight="5dp"     
    android:textAppearance="?android:attr/textAppearanceLarge" />

</LinearLayout>

layout_newLine is not working in inflated layout, which works if i have all the textview in the parent layout. any suggestion please

naren
  • 71
  • 2