将滚动视图调整到Android中的可用空间
我的滚动视图有问题。我想把它放在可用的空间里,但我不知道怎么做 现在,在一个线性布局之前有了ScrollView和TextView:将滚动视图调整到Android中的可用空间,android,android-layout,layout,Android,Android Layout,Layout,我的滚动视图有问题。我想把它放在可用的空间里,但我不知道怎么做 现在,在一个线性布局之前有了ScrollView和TextView: <ScrollView android:id="@+id/scrollView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1"
<ScrollView
android:id="@+id/scrollView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:fillViewport="true"
android:layout_alignParentLeft="true"
android:layout_below="@+id/previousimage"
android:layout_marginTop="@dimen/margin">
<TextView
android:id="@+id/question_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margintop"
android:gravity="center_horizontal"
android:paddingBottom="@dimen/margin_five"
android:scrollbars="vertical"
android:textColor="@color/white"
android:textSize="@dimen/common_textsize" />
</ScrollView>
<LinearLayout
android:id="@+id/bottom_options"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_below="@+id/scrollView"
android:layout_marginTop="@dimen/margin_small"
android:gravity="center|bottom"
android:orientation="vertical">
问题是,如果我的文本视图中有太多的文本,线性布局会下降并隐藏。我想滚动其中的文本。无需向下推动管路布置
我想让ScrollView自动占据这个空间,以适应所有屏幕大小
谢谢大家! 滚动视图应始终
匹配父项(或至少小于可用空间),否则它只占用与其子项相同的空间,因此从其角度来看,没有子项,因此无需滚动。滚动视图应始终匹配父项(或至少小于可用空间)否则,它只占用与其子对象相同的空间,因此从其角度来看,没有子对象,因此无需滚动。在滚动视图之前定义LinearLayout,并将ScrollView设置为高于LinearLayout,匹配父对象。像这样:
<LinearLayout
android:id="@+id/bottom_options"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginTop="@dimen/margin_small"
android:gravity="center|bottom"
android:orientation="vertical">
...
</LinearLayout>
<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:fillViewport="true"
android:layout_alignParentLeft="true"
android:layout_below="@+id/previousimage"
android:layout_above="@+id/bottom_options"
android:layout_marginTop="@dimen/margin">
<TextView
android:id="@+id/question_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margintop"
android:gravity="center_horizontal"
android:paddingBottom="@dimen/margin_five"
android:scrollbars="vertical"
android:textColor="@color/white"
android:textSize="@dimen/common_textsize" />
</ScrollView>
...
在ScrollView之前定义LinearLayout,并将ScrollView设置为高于LinearLayout,匹配父项。像这样:
<LinearLayout
android:id="@+id/bottom_options"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginTop="@dimen/margin_small"
android:gravity="center|bottom"
android:orientation="vertical">
...
</LinearLayout>
<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:fillViewport="true"
android:layout_alignParentLeft="true"
android:layout_below="@+id/previousimage"
android:layout_above="@+id/bottom_options"
android:layout_marginTop="@dimen/margin">
<TextView
android:id="@+id/question_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margintop"
android:gravity="center_horizontal"
android:paddingBottom="@dimen/margin_five"
android:scrollbars="vertical"
android:textColor="@color/white"
android:textSize="@dimen/common_textsize" />
</ScrollView>
...
我认为你的线性布局在这里没用。嗨,看看这个。我觉得你的线性布局在这里没用。嗨,看看这个。如果我在ScrollView中设置:android:layout\u width=“match\u parent”android:layout\u height=“match\u parent”,则线性布局将完全隐藏。您的线性布局为空,因此其高度将为0。如果需要在ScrollView下显示LinearLayout,则应将其嵌入到父布局中。LinearLayout已填充,但我尚未粘贴内容。现在我有了这个。但如果我有这么多的文字。ScrollView无法工作并将我的线性布局推到屏幕外。如果我在ScrollView中设置此:android:layout\u width=“match\u parent”android:layout\u height=“match\u parent”,则线性布局将完全隐藏。您的线性布局为空,因此其高度将为0。如果需要在ScrollView下显示LinearLayout,则应将其嵌入到父布局中。LinearLayout已填充,但我尚未粘贴内容。现在我有了这个。但如果我有这么多的文字。ScrollView无法工作,请将我的线性布局推到屏幕外。谢谢!这件作品太完美了!现在我有一个“文本视图”和文本内的问题。它在底部显示文本,我想在ScrollView的中心显示。ScrollView和TextView都有“android:layout_marginTop”。我认为这是重复的,所以你的文字去底部。另外,如果你想让文本“水平居中”,那么你需要将android:layout\u width更改为“match\u parent”。谢谢!这件作品太完美了!现在我有一个“文本视图”和文本内的问题。它在底部显示文本,我想在ScrollView的中心显示。ScrollView和TextView都有“android:layout_marginTop”。我认为这是重复的,所以你的文字去底部。另外,如果你想让文本“水平居中”,那么你需要将android:layout\u width更改为“match\u parent”。