Example #1
0
        /// <summary>
        /// Scrolls the specified widget to the specified coordinates, except
        /// constrains the X scrolling position to the horizontal regions of
        /// the text that will be visible after scrolling to the specified
        /// Y position.
        /// </summary>
        /// <remarks>
        /// Scrolls the specified widget to the specified coordinates, except
        /// constrains the X scrolling position to the horizontal regions of
        /// the text that will be visible after scrolling to the specified
        /// Y position.
        /// </remarks>
        public static void scrollTo(android.widget.TextView widget, android.text.Layout layout
                                    , int x, int y)
        {
            int verticalPadding = widget.getTotalPaddingTop() + widget.getTotalPaddingBottom(
                );
            int top    = layout.getLineForVertical(y);
            int bottom = layout.getLineForVertical(y + widget.getHeight() - verticalPadding);
            int left   = int.MaxValue;
            int right  = 0;

            android.text.Layout.Alignment?a = layout.getParagraphAlignment(top);
            bool ltr = layout.getParagraphDirection(top) > 0;
            {
                for (int i = top; i <= bottom; i++)
                {
                    left  = (int)System.Math.Min(left, layout.getLineLeft(i));
                    right = (int)System.Math.Max(right, layout.getLineRight(i));
                }
            }
            int hoizontalPadding = widget.getTotalPaddingLeft() + widget.getTotalPaddingRight
                                       ();
            int availableWidth = widget.getWidth() - hoizontalPadding;
            int actualWidth    = right - left;

            if (actualWidth < availableWidth)
            {
                if (a == android.text.Layout.Alignment.ALIGN_CENTER)
                {
                    x = left - ((availableWidth - actualWidth) / 2);
                }
                else
                {
                    if ((ltr && (a == android.text.Layout.Alignment.ALIGN_OPPOSITE)) || (a == android.text.Layout.Alignment
                                                                                         .ALIGN_RIGHT))
                    {
                        // align_opposite does NOT mean align_right, we need the paragraph
                        // direction to resolve it to left or right
                        x = left - (availableWidth - actualWidth);
                    }
                    else
                    {
                        x = left;
                    }
                }
            }
            else
            {
                x = System.Math.Min(x, right - availableWidth);
                x = System.Math.Max(x, left);
            }
            widget.scrollTo(x, y);
        }
Example #2
0
		private int getScrollBoundsRight(android.widget.TextView widget)
		{
			android.text.Layout layout = widget.getLayout();
			int topLine = getTopLine(widget);
			int bottomLine = getBottomLine(widget);
			if (topLine > bottomLine)
			{
				return 0;
			}
			int right_1 = int.MinValue;
			{
				for (int line = topLine; line <= bottomLine; line++)
				{
					int lineRight = (int)System.Math.Ceiling(layout.getLineRight(line));
					if (lineRight > right_1)
					{
						right_1 = lineRight;
					}
				}
			}
			return right_1;
		}