【问题标题】:LinearLayout onShow it moves the ScrollView downLinearLayout onShow 它将 ScrollView 向下移动
【发布时间】:2018-01-23 08:06:47
【问题描述】:

我想在 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 的原因是因为我有一些自定义数据显示水平和其他垂直。

【问题讨论】:

  • 您的代码似乎运行良好。 onething block1 完全不可见或滚动视图滚动到块 2 并且块 1 停留在顶部。
  • 如果您可以发布结果与预期结果,那就太好了

标签: java android android-layout scrollview android-linearlayout


【解决方案1】:

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

<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>

【讨论】:

    猜你喜欢
    • 2019-08-26
    • 1970-01-01
    • 2015-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多