[英]Horizontal scroll view with child TextViews not scrolling
I am showing the user some stats. 我正在向用户显示一些统计信息。 There is a lot of information on the screen so space is cramped.
屏幕上有很多信息,因此空间狭窄。 I decided to use a horizontal scroll view which contains 9 TextViews in total.
我决定使用水平滚动视图,该视图总共包含9个TextView。 However, I only want to display three of these text views at a time.
但是,我只想一次显示其中三个文本视图。
Like so: 像这样:
(The arrow is a just separate image view that just show's the user they can scroll) (箭头是一个单独的图像视图,仅显示其可以滚动的用户)
This is fine and how I want it to look. 很好,我希望它看起来如何。 However, there is 6 other stats which I need to show.
但是,还有6个其他统计数据需要显示。 I wish to be able to scroll to the right and three new text views to appear (and back to the left when I get to the last three stats).
我希望能够向右滚动,然后出现三个新的文本视图(当我获得最后三个统计数据时,再回到左侧)。 This horizontal scroll view is the parent of a LinearLayout which has 9 child TextViews.
此水平滚动视图是LinearLayout的父级,LinearLayout具有9个子TextViews。 I tried putting every three TextViews in there own linear layouts but was prevented because the Horizontal Scroll View can only have one LinearLayout child.
我尝试将每三个TextView放置在自己的线性布局中,但由于“水平滚动视图”只能有一个LinearLayout子级而被阻止。
I currently have the other 6 stats visibility to gone
because they are currently added below the top 3 stats in a vertical order like this image shows: 我现在有其他6个统计知名度
gone
,因为它们在垂直顺序当前加入下面的前3名的统计是这样的图像所示:
My plan was originally to pro-grammatically display the next three stats and hide the original when scrolled but before I programmed this I tested to see if the first three were scroll-able but they don't react when I try to scroll. 我的计划本来是按语法显示接下来的三个状态,并在滚动时隐藏原始状态,但是在编写此程序之前,我测试了一下前三个状态是否可滚动,但是当我尝试滚动时它们没有反应。
How do I got about this? 我怎么知道的?
Here is my current xml: 这是我当前的xml:
<HorizontalScrollView
android:id="@+id/sv_horizontalP1Stats"
android:layout_width="0dp"
android:layout_height="97dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
app:layout_constraintBottom_toBottomOf="@+id/sv_horizontalP2Stats"
app:layout_constraintEnd_toStartOf="@+id/sv_player1PastScores"
app:layout_constraintHorizontal_bias="0.596"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/iv_navArrowP1">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/tv_legAvg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical"
android:text="@string/tv_LegAVG"
android:textSize="13sp" />
<TextView
android:id="@+id/tv_matchAVG"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical"
android:text="@string/tv_MatchAVG"
android:textSize="13sp" />
<TextView
android:id="@+id/tv_first6Avg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical"
android:text="@string/tv_first6AVG"
android:textSize="13sp" />
<TextView
android:id="@+id/tv_100plus"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/tv_100plus"
android:visibility="gone" />
<TextView
android:id="@+id/tv_140Plus"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/tv_140plus"
android:visibility="gone" />
<TextView
android:id="@+id/tv_180s"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/tv_180"
android:visibility="gone" />
<TextView
android:id="@+id/tv_bestFinish"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/tv_bestFinish"
android:visibility="gone" />
<TextView
android:id="@+id/tv_bestLeg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/tv_BestLeg"
android:visibility="gone" />
<TextView
android:id="@+id/tv_doublesPercentage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/tv_doubles"
android:visibility="gone" />
</LinearLayout>
</HorizontalScrollView>
All you need to do is create multiple linear layouts inside your main linear layout. 您需要做的就是在主线性布局中创建多个线性布局。 Each containing 3 textviews and change the orientation of main linear layout to horizontal and you're good to go.
每个视图都包含3个textview,并将主要线性布局的方向更改为水平,然后就可以了。
eg : 例如:
<HorizontalScrollView
android:id="@+id/sv_horizontalP1Stats"
android:layout_width="0dp"
android:layout_height="97dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
app:layout_constraintBottom_toBottomOf="@+id/sv_horizontalP2Stats"
app:layout_constraintEnd_toStartOf="@+id/sv_player1PastScores"
app:layout_constraintHorizontal_bias="0.596"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/iv_navArrowP1">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"> <!-- Changing orientation to horizontal -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"> <!-- Group 1 of TV -->
<TextView
android:id="@+id/tv_legAvg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="@string/tv_LegAVG"
android:textSize="13sp" />
<TextView
android:id="@+id/tv_matchAVG"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="@string/tv_MatchAVG"
android:textSize="13sp" />
<TextView
android:id="@+id/tv_first6Avg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="@string/tv_first6AVG"
android:textSize="13sp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"> <!-- Group 2 -->
// .. Next three
</LinearLayout>
// .. And soo on
</LinearLayout>
</HorizontalScrollView>`
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.