Я отображаю текст OCR в текстовом представлении, но некоторые строки в моем текстовом представлении не достигают ширины экрана. Но некоторые строки доходят до конца. Я понятия не имею, как это сделать, пожалуйста, помогите мне.
Если вы видите мои выходные данные в текстовом представлении, у меня все еще есть пробел, чтобы расширить мою строку, но он отображается как новая строка
мой вывод текстового представления
It is with great enthusiasm that I accept the Foreign
Service Officer position with the
Department of State.
I feel confident that I can make a significant contribution to the
agency.
xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff006064">
<Button
android:text="Pick Image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/MyButton" />
<ImageView
android:src="@android:drawable/ic_menu_gallery"
android:layout_width="match_parent"
android:layout_height="295.0dp"
android:id="@+id/imageView1" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/txtView"
android:layout_width="350dp"
android:layout_height="wrap_content"
android:text="No Text"
android:scrollbars="vertical|horizontal"
android:textStyle="bold"
android:textColor="#ffffffff"
android:textIsSelectable="true"
android:layout_marginLeft="25dp"
android:layout_weight="1"
android:ellipsize="end"/>
</ScrollView>
</LinearLayout>
.cs file
TextRecognizer txtRecognizer = new TextRecognizer.Builder(ApplicationContext).Build();
if (!txtRecognizer.IsOperational)
{
Log.Error("Error", "Detector dependencies are not yet available");
}
else
{
Frame frame = new Frame.Builder().SetBitmap(bitmap).Build();
SparseArray items = txtRecognizer.Detect(frame);
StringBuilder strBuilder = new StringBuilder();
for (int i = 0; i < items.Size(); i++)
{
TextBlock item = (TextBlock)items.ValueAt(i);
strBuilder.Append(item.Value);
strBuilder.Append("/n");
}
int myLimit = 8;
string sentence = strBuilder.ToString();
string[] words = sentence.Split("/n",' ');
StringBuilder newSentence = new StringBuilder();
string line =".";
foreach (string word in words)
{
if ((line + word).Length > myLimit)
{
newSentence.AppendLine(line);
line = " ";
}
line += string.Format("{0} ", word);
}
if (line.Length > 0)
newSentence.AppendLine(line);
txtView.Text= newSentence.ToString();
}
}