gpt4 book ai didi

java - LinearLayout onShow 它将 ScrollView 向下移动

转载 作者:太空宇宙 更新时间:2023-11-04 10:46:08 24 4
gpt4 key购买 nike

我想在 ScrollView 顶部显示我的 notification_bar_linearlayout

在填充 ScrollView 中的数据后,我将在代码中显示 notification_bar_linearlayout

但是当我展示时:

notification_bar_linearlayout.setVisibility(View.VISIBLE);

ScrollView内的数据会自动滚动到中间。这意味着在屏幕上将显示以下内容:

notification_bar_linearlayout

block_two

因此block_one不再可见。

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

//Notification bar
<LinearLayout
android:id="@+id/notification_bar_linearlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
android:background="@color/white_color"
android:paddingLeft="20dip"
android:paddingRight="20dip"
android:paddingTop="15dip"
android:paddingBottom="15dip"
android:visibility="gone">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
//My TextView for the bar
</RelativeLayout>
</LinearLayout>

//List datas
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="@+id/block_one"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
//My frist block for the top of the list
</LinearLayout>

<LinearLayout
android:id="@+id/block_two"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
//My second block for the bottom of the list
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
</FrameLayout>
</LinearLayout>

附注之所以有这么多 LinearLayout 是因为我有一些自定义数据显示水平和其他垂直。

最佳答案

没有截图很难理解,但也许你需要这样设置权重:

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

//Notification bar
<LinearLayout
android:layout_weight="0.5"
android:id="@+id/notification_bar_linearlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
android:background="@color/white_color"
android:paddingLeft="20dip"
android:paddingRight="20dip"
android:paddingTop="15dip"
android:paddingBottom="15dip"
android:visibility="gone">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
//My TextView for the bar
</RelativeLayout>
</LinearLayout>

//List datas
<ScrollView
android:layout_weight="0.5"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="@+id/block_one"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
//My frist block for the top of the list
</LinearLayout>

<LinearLayout
android:id="@+id/block_two"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
//My second block for the bottom of the list
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
</FrameLayout>
</LinearLayout>

关于java - LinearLayout onShow 它将 ScrollView 向下移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48396853/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com