Layout Weights do not work inside a ScrollView

后端 未结 5 920
被撕碎了的回忆
被撕碎了的回忆 2020-11-29 21:22

I want to assign layout weights to several items within a LinearLayout inside of a ScrollView. However, the ScrollView ignores the

相关标签:
5条回答
  • 2020-11-29 21:29

    just put this in your scroll view:

    android:fillViewport="true"

    0 讨论(0)
  • 2020-11-29 21:40

    Add below line in your ScrollView it will be work fine.

    Only single child must be there for ScrollView

    android:fillViewport="true"
    
    0 讨论(0)
  • 2020-11-29 21:43

    I have faced this problem before. Just use android:fillViewport="true" in your ScrollView and it will fill up the screen.

    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/scrollView1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:fillViewport="true" >
    
    0 讨论(0)
  • 2020-11-29 21:49

    This won't work as you have done it. The child view of a ScrollView should be set to wrap_content. If you set it to fill_parent, it will fill the area of the ScrollView and never scroll, because it won't be larger than the ScrollView.

    The idea of layout_weight is to fill a specific area proportionately.

    You should set all of the child LinearLayouts layout_height to either wrap_content or a specific size (in dp) and the parent LinearLayout layout_height to wrap_content

    As said you need to remove the additional

    xmlns:android="http://schemas.android.com/apk/res/android"

    if it's not the root (first) element of the layout.

    0 讨论(0)
  • 2020-11-29 21:49

    In my experience, fillviewport=true works bit strange.

    I solved this problem by wrapping LinearLayout with another Layout like FrameLayout.

    I hope this helps.

    0 讨论(0)
提交回复
热议问题