【发布时间】:2018-08-18 15:47:59
【问题描述】:
嗨,我正在运行一个循环 10 次,每次我创建一个新的 TextView 并且我将该 textview 添加到我的线性布局中,其方向设置为“水平”。我想以段落的形式显示这些文本,另一个句子开始于一个句子结束的地方。
这是我的布局:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="match_parent"
android:layout_width="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".ui.QuestionActivity"
android:padding="16dp"
android:orientation="vertical"
tools:showIn="@layout/activity_question">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/title"
android:layout_gravity="center"
android:textAppearance="?android:textAppearanceLarge"
android:textColor="@android:color/black"
android:textStyle="bold|italic"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_marginTop="10dp"
android:id="@+id/base_layout"/>
</LinearLayout>
</ScrollView>
这是我的java代码:
for(int i=0; i<10; i++){
TextView textView = Utility.getTextView(this, i);
if(i == 5) {
textView.setText(sentences.get(i) + "\n" + "\n");
}
else {
textView.setText(sentences.get(i) + " ");
}
mLayout.addView(textView);
}
但问题是只有当方向设置为“水平”时才会显示第一个文本视图,如果我将方向设置为“垂直”,我能够看到彼此下方的所有文本视图。
请帮帮我。
【问题讨论】:
-
您是否尝试在语法上设置方向?
-
不工作尝试谢谢
标签: java android android-layout android-linearlayout textview