Android:如何在ScrollView布局下显示文本视图?

Android:如何在ScrollView布局下显示文本视图?,android,android-layout,textview,Android,Android Layout,Textview,我试图在UI的底部显示一个带有居中文本视图的矩形框作为页脚栏(就像工具栏/操作栏显示为主UI上方的页眉栏一样)。TextView应该位于主UI(滚动视图)的下方,并且TextView根本不显示。其他一切都显示正确。你知道我做错了什么吗 layout.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android

我试图在UI的底部显示一个带有居中文本视图的矩形框作为页脚栏(就像工具栏/操作栏显示为主UI上方的页眉栏一样)。TextView应该位于主UI(滚动视图)的下方,并且TextView根本不显示。其他一切都显示正确。你知道我做错了什么吗

layout.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout

xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:focusableInTouchMode="true"
tools:context=".CardViewActivity">

<include
    android:id="@+id/toolbar"
    layout="@layout/toolbar" >
</include>

<ScrollView
    android:id="@+id/ScrollView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    ...>
...
</ScrollView>

<TextView
    android:id="@+id/skychilltext2"
    android:text="skychill"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:textStyle="bold"
    android:textColor="#FFFFFF"
    android:background="@color/colorPrimary"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:clickable="true"  />

</LinearLayout>    

...
试试下面的方法

<RelativeLayout
  (...)>

    <LinearLayout android:id="@+id/ll1"
        android:layout_alignParentTop="true"
        (...)/>

    <TextView android:id="@+id/button"
        android:layout_alignParentBottom="true"
        (...)/>

    <ScrollView
         android:layout_above="@id/button"
         android:layout_below="@id/ll1"
         (...)/>

</RelativeLayout>

有关参考信息,请参见此处或尝试以下内容

<RelativeLayout
  (...)>

    <LinearLayout android:id="@+id/ll1"
        android:layout_alignParentTop="true"
        (...)/>

    <TextView android:id="@+id/button"
        android:layout_alignParentBottom="true"
        (...)/>

    <ScrollView
         android:layout_above="@id/button"
         android:layout_below="@id/ll1"
         (...)/>

</RelativeLayout>


如需参考,请参见此处或设置android:layout:weight on TextView。

设置android:layout:weight on TextView。

由于您将高度设置为
match\u parent
,因此它将占用所有房间。我不确定你到底想要什么,但你可以在上面加一个砝码,尽可能地扩大空间

<ScrollView
    android:id="@+id/ScrollView1"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1" 
    ...>
    ...
</ScrollView>

因为您将高度设置为
match\u parent
,所以它将占用所有房间。我不确定你到底想要什么,但你可以在上面加一个砝码,尽可能地扩大空间

<ScrollView
    android:id="@+id/ScrollView1"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1" 
    ...>
    ...
</ScrollView>

您需要加权和来缩放布局。您的代码集与高度滚动视图的父级匹配

<ScrollView
android:id="@+id/ScrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" 
...>

。。。

您需要加权和来缩放布局。您的代码集与高度滚动视图的父级匹配

<ScrollView
android:id="@+id/ScrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" 
...>

。。。
问题在于ScrollView中的android:layout\u height=“match\u parent”。它指示LinearLayout为其提供所有高度,不为TextView留下任何内容

更改滚动视图:

android:layout_height="wrap_content"
android:layout_weight="1"
更改文本视图:

android:layout_weight="0"

问题是ScrollView中的android:layout\u height=“match\u parent”。它指示LinearLayout为其提供所有高度,不为TextView留下任何内容

更改滚动视图:

android:layout_height="wrap_content"
android:layout_weight="1"
更改文本视图:

android:layout_weight="0"

好的,将TextView布局权重设置为零有什么作用?与根本不设置权重相比?布局为_weight=“0”的视图不会展开以占用LinearLayout中的可用空间,我不明白。如果将TextView的布局权重设置为零,则表示TextView根本不会显示,因为线性布局中没有可用空间?否。值“0”表示它不会参与额外可用空间的分配,并且只占用内容所需的空间。好的,将TextView布局权重设置为零有什么作用?与根本不设置权重相比?布局为_weight=“0”的视图不会展开以占用LinearLayout中的可用空间,我不明白。如果将TextView的布局权重设置为零,则表示TextView根本不会显示,因为线性布局中没有可用空间?否。值“0”表示它不会参与额外可用空间的分配,并且只占用内容所需的空间。好的,那么我是否需要为TextView设置任何布局权重,或者干脆省去它?省去它。不需要。将其保留为wrap content,这意味着TextView的视图将只足够大,以包装文本内容,并且所有剩余的垂直空间将分配给ScrollView,对吗?好的,那么我需要为TextView设置任何布局权重还是省略?省略它。不需要。将其保留为wrapp content,这意味着TextView的视图将仅足够大以包装文本内容,并且所有剩余的垂直空间将分配给ScrollView,正确吗?好的,从线性布局切换到相对布局有什么缺点吗?好的,从线性布局切换到相对布局有什么缺点吗?