Android 滚动视图隐藏布局中的第一个子项
我在Android 滚动视图隐藏布局中的第一个子项,android,android-scrollview,Android,Android Scrollview,我在LinearLayout中有一些小部件,它是ScrollView的子项。问题在于,本例中的第一个小部件,名为“Title 1”的小部件不可见,它超出了如图所示的屏幕大小 我尝试了以下内容,但仍然没有显示我的标题1 在ScrollView中添加了一个属性android:fillViewport=“true”,但它不起作用 添加了一个layout_gravity(center_horizontal | center_vertical)属性,但它不起作用 这个问题专门针对OP的设计,没有多大帮助
LinearLayout
中有一些小部件,它是ScrollView
的子项。问题在于,本例中的第一个小部件,名为“Title 1”的小部件不可见,它超出了如图所示的屏幕大小
我尝试了以下内容,但仍然没有显示我的标题1
ScrollView
中添加了一个属性android:fillViewport=“true”
,但它不起作用layout_gravity
(center_horizontal | center_vertical
)属性,但它不起作用<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/view_pager"
android:fillViewport="true"
android:focusableInTouchMode="true"
app:layout_constraintBottom_toTopOf="@+id/tabLayout"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="10dp"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:text="Title 1"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 2"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 3"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 4"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 5"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 6"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 7"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 8"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 9"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 10"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 11"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 12"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 13"
/>
</LinearLayout>
</ScrollView>
<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
style="@style/tabLayoutStyle"
app:layout_constraintBottom_toBottomOf="parent"
/>
</android.support.constraint.ConstraintLayout>
</LinearLayout>
编辑1
将LinearLayout(滚动视图内部)的高度从
match\u parent
更改为wrap\u content
,但仍然不起作用。删除表格布局,然后将出现第一个文本视图。问题是您错误地使用了TabLayout删除TabLayout,然后会出现第一个文本视图。问题在于您使用的表格布局错误您的表格布局
可能是第一个值不可见的原因。列表中的第一项可能位于表格布局下,并且不可见
不需要约束布局
。将线性布局的方向设置为垂直。您可以使用此示例
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
style="@style/tabLayoutStyle"
/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/view_pager"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="10dp"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:text="Title 1"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 2"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 3"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 4"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 5"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 6"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 7"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 8"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 9"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 10"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 11"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 12"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 13"
/>
</LinearLayout>
</ScrollView>
您的表格布局
可能是第一个值不可见的原因。列表中的第一项可能位于表格布局下,并且不可见
不需要约束布局
。将线性布局的方向设置为垂直。您可以使用此示例
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
style="@style/tabLayoutStyle"
/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/view_pager"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="10dp"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:text="Title 1"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 2"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 3"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 4"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 5"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 6"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 7"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 8"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 9"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 10"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 11"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 12"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 13"
/>
</LinearLayout>
</ScrollView>
结果是添加到post
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/view_pager"
android:fillViewport="true"
android:focusableInTouchMode="true"
app:layout_constraintBottom_toTopOf="@+id/tabLayout"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:text="Title 1"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 2"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 3"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 4"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 5"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 6"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 7"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 8"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 9"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 10"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 11"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 12"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 13"/>
</LinearLayout>
</ScrollView>
<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
android:layout_height="50dp"
android:background="@color/colorAccent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_width="match_parent"/>
</android.support.constraint.ConstraintLayout>
</LinearLayout>
结果是添加到post
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/view_pager"
android:fillViewport="true"
android:focusableInTouchMode="true"
app:layout_constraintBottom_toTopOf="@+id/tabLayout"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:text="Title 1"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 2"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 3"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 4"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 5"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 6"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 7"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 8"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 9"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 10"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 11"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 12"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 13"/>
</LinearLayout>
</ScrollView>
<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
android:layout_height="50dp"
android:background="@color/colorAccent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_width="match_parent"/>
</android.support.constraint.ConstraintLayout>
</LinearLayout>
除此之外,我添加了以下属性,它工作得非常完美
我添加了这个属性,app:layout\u constraintTop\u toTopOf=“parent”
,它将滚动视图与顶部对齐,防止子视图超出设备高度,但随后又出现了另一个问题,底部的视图
被表格布局隐藏了
,因此我添加了这个属性来纠正这个问题,将布局高度
更改为包裹内容
,并添加了这个,应用程序:布局约束高度=“true”“
此属性不超过生成的维度,在本例中,该维度为tabLayout
。这是从约束布局版本1.1开始的,请参阅
同样的,它也完美地描述了它
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/view_pager"
android:fillViewport="true"
android:focusableInTouchMode="true"
app:layout_constrainedHeight=”true"
app:layout_constraintBottom_toTopOf="@+id/tabLayout"
app:layout_constraintTop_toTopOf="parent">
除此之外,我添加了以下属性,它工作得非常完美
我添加了这个属性,app:layout\u constraintTop\u toTopOf=“parent”
,它将滚动视图与顶部对齐,防止子视图超出设备高度,但随后又出现了另一个问题,底部的视图
被表格布局隐藏了
,因此我添加了这个属性来纠正这个问题,将布局高度
更改为包裹内容
,并添加了这个,应用程序:布局约束高度=“true”“
此属性不超过生成的维度,在本例中,该维度为tabLayout
。这是从约束布局版本1.1开始的,请参阅
同样的,它也完美地描述了它
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/view_pager"
android:fillViewport="true"
android:focusableInTouchMode="true"
app:layout_constrainedHeight=”true"
app:layout_constraintBottom_toTopOf="@+id/tabLayout"
app:layout_constraintTop_toTopOf="parent">
此问题仅在预览屏幕中出现?将LInearLayout(内部滚动视图)的高度从match_parent
更改为wrap_content
@user7832102已在物理设备和模拟器上试用。@Piyush做到了这一点仍然不走运!您的项目主题样式是什么?此问题仅在预览屏幕中出现?将LInearLayout(内部滚动视图)的高度从match\u parent
更改为wrap\u content
@user7832102在物理设备和模拟器上进行了尝试。@piyus这样做还是不走运!你的项目主题风格是什么?列表中的第一项可能在TabLayout下,不可见。
完全错误你怎么会看我的代码?不需要布局。使直线布局的方向垂直。您可以使用此示例
How come man我需要底部的选项卡布局,您已根据自己的意愿将其放置在顶部。选项卡需要在底部,小部件应该被底部的选项卡布局隐藏。@GeekDroid如果你想让TabLayout在底部,请将它放在ScrollView后面,这样会隐藏TextView的11,12,13(如果你能理解的话)@GeekDroid试试看,不应该这样做。将TabLayout放在屏幕底部不是标准做法列表中的第一项可能在TabLayout下面,并且不可见。
完全错误您怎么会看我的代码?不需要布局。使直线布局的方向垂直。您可以使用此示例
How come man我需要底部的选项卡布局,您已根据自己的意愿将其放置在顶部。选项卡需要位于底部,小部件应该被底部的选项卡布局隐藏。@GeekDroid,如果您想要