【问题标题】:Scollview doesn't scroll a Linearlayout with layout_gravity="bottom"Scrollview 不会滚动带有 layout_gravity="bottom" 的 Linearlayout
【发布时间】:2023-04-07 08:04:01
【问题描述】:

我有一个 Scrollview 和一个 LinearLayout 作为它的孩子。我将Linearlayout的layout_gravity设置为“bottom”,因为我想以编程方式将一些自定义视图添加到Lineararlayout,这些视图被layoutgravity“bottom”拖到底部。 我尝试将“top”设置为 layout_gravity,并且滚动视图按应有的方式滚动, 但是当我将它设置为“底部”时,它不再滚动了。(自定义视图已经插入并且需要超过可用高度)

有什么建议吗? 提前致谢!

这是我的代码:

    <ScrollView
        android:layout_width="match_parent"
        android:scrollbarAlwaysDrawVerticalTrack="true"
        android:background="#fff"
        android:id="@+id/scrollView"
        android:fillViewport="true"
        android:scrollbars="none"
        android:layout_height="match_parent">

            <LinearLayout
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:id="@+id/linearLayout"
                android:layout_gravity="bottom"
                android:layout_height="match_parent">

                <!--Here are a few custom views added via code-->

            </LinearLayout>
    </ScrollView>

【问题讨论】:

    标签: android scroll scrollview android-linearlayout layout-gravity


    【解决方案1】:

    也许您在 LinearLayout 中设置了android:layout_height="match_parent" 是问题所在。试试wrap_content 看看是否有帮助。

    【讨论】:

    • 没有帮助 :( 我在此 Scrollview 下方有一个 Edittext。这可能会影响 scrollview 的可滚动性吗?
    【解决方案2】:

    在滚动视图关闭后添加文本视图(您希望底部不滚动的内容)并为您想要的内容添加属性:

            <LinearLayout>
    
                <!--Here are a few custom views Which you want to scroll added via code-->
    
            </LinearLayout>
    </ScrollView>                                                                
    <!--Here are a few custom views Which you want to show at bottom without scrolling
        like <TextView> with gravity bottom attribute-->
    </LinearLayout>               
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多