1

I am trying to create an Android app where data is read and alignment differs if a certain string is contained in the data. The data is then appended onto a textview with a carriage return. Using append, is there any way for me to change the text alignment for individual line entries? Currently what I've been doing is this

if(returnedData.contains(myVar)) {
         myTextView.setGravity(Gravity.END);
} else {
         myTextView.setGravity(Gravity.START);
}

Obviously this does not work because it changes the alignment of every line with each new append. Thank you ahead of time for any help.

jjo
  • 154
  • 2
  • 14
  • You mean if you have three lines of string than only lets say first line alignment should be different and two of them should be align differently in one textview? – Faizzy Sep 13 '19 at 04:23
  • @MohdFaizan Exactly, if it contains a certain string the alignment changes to right, if not, it doesn't – jjo Sep 13 '19 at 20:24

1 Answers1

0

android:layout_gravity is used to align the text view with respect to the parent layout. android:gravity is used to align the text inside the text view.

put these lines in your xml

Further make sure that you are trying to align the text inside the textview to the right or do you want to move the text view itself to the right with respect to the parent layout, solution will differ with different scenario.

also you can take two different textview and align that textview rather than setting them on single textview.

Geekfreak
  • 13
  • 10