Java 向水平线性布局添加多个文本视图
嗨,我运行了10次循环,每次我创建一个新的TextView,我将TextView添加到我的线性布局中,该布局的方向设置为“水平”。我想以段落的形式展示这些文本,其中一个句子开始,另一个句子结束 这是我的布局:Java 向水平线性布局添加多个文本视图,java,android,android-layout,android-linearlayout,textview,Java,Android,Android Layout,Android Linearlayout,Textview,嗨,我运行了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:/
<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);
}
对于(int i=0;i您应该需要将基本布局LinearLayout
包装在水平滚动视图下
试试下面,应该可以解决你的问题。我已经验证了自己
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="horizontal">
<LinearLayout
android:id="@+id/base_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:orientation="horizontal" />
</HorizontalScrollView>
您是否尝试按语法设置方向。?thanksThanks@Krishna Sharma不工作,但这意味着我的文本视图将水平滚动,我不希望这样,我希望以段落的形式显示它们,然后所有文本视图将不会在屏幕上水平显示。这就是您的情况。那么我应该如何我想知道为什么没有显示这些文本。只有“方向垂直”选项。如果要水平显示,则必须在“水平滚动视图”下包装布局。如果从布局中删除“滚动视图”,则即使是垂直方向,也无法显示所有文本视图。无论如何,您需要有克罗林无论是垂直的还是水平的。