Skip to content

Commit

Permalink
Some changes for Right-To-Left languages
Browse files Browse the repository at this point in the history
I modified some lines for RTL languages like Persian or Arabic
  • Loading branch information
miladrasooli committed Apr 12, 2014
1 parent 523a9d4 commit 255d500
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/TextViewEx.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ protected void onDraw(Canvas canvas)
paint.setColor(getCurrentTextColor());
paint.setTypeface(getTypeface());
paint.setTextSize(getTextSize());
paint.setTextAlign(Align.RIGHT);

//minus out the paddings pixel
dirtyRegionWidth = getWidth()-getPaddingLeft()-getPaddingRight();
Expand Down Expand Up @@ -192,20 +193,18 @@ else if(block.equals("\n"))

}
else if(j==0){
//if it is the first word of the line, text will be drawn starting from position getPaddingLeft()
activeCanvas.drawText(word, getPaddingLeft(), verticalOffset, paint);
// add in the left padding pixel length to the horizontalOffset
horizontalOffset+=getPaddingLeft();
//if it is the first word of the line, text will be drawn starting from right edge of textview
activeCanvas.drawText(word, getWidth()-(getPaddingRight()), verticalOffset, paint);
// add in the paddings to the horizontalOffset
horizontalOffset+=getWidth()-(getPaddingRight());

}
else
{
activeCanvas.drawText(word, horizontalOffset, verticalOffset, paint);


}

horizontalOffset += paint.measureText(word) + spaceOffset + strecthOffset;
horizontalOffset -= paint.measureText(word) + spaceOffset + strecthOffset;
}

lines++;
Expand Down

1 comment on commit 255d500

@HamidrezaAmz
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi milad
thanks for this edition, this is ok, but how to add spans to this justified textview? we need to add spans too, do you have any idea? please share it.
tnx

Please sign in to comment.