代码之家  ›  专栏  ›  技术社区  ›  Animesh Jena

ScrollView未向下滚动

  •  1
  • Animesh Jena  · 技术社区  · 7 年前

    我知道这是一个非常基本的问题。我还是解决不了。我在标题视图下面有一个滚动视图,滚动视图根本不滚动。我会把我的密码贴在下面。请看一下。

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/page_background"
    android:clickable="true"
    android:orientation="vertical"
    >
    
     <RelativeLayout
       android:layout_width="match_parent"
       android:layout_height="?android:attr/actionBarSize"
       android:gravity="center_vertical"
       android:layout_weight="0"
       android:clickable="true"
       android:background="@color/button_colour">
     </RelativeLayout>
    
     <ScrollView
      android:layout_width="match_parent"
      android:layout_height="0dp"
      android:layout_weight="1"
      android:fillViewport="true"
     >
     <LinearLayout
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       android:weightSum="14"
       android:padding="2dp"
       android:clickable="true"
       android:orientation="vertical">
     </LinearLayout>
    
     </ScrollView>
    
     </LinearLayout>
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   ADM    7 年前

    没有用的 android:layout_weight 在这种情况下。而且你不必使用 安卓:布局重量 里面 ScrollView . 如果你使用 Views 将包裹在 ViewGroup 不会滚动。和 fill_parent 使用不当 match_parent .

    使用下面的布局:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linearLayout"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_height="match_parent">
    
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="?android:attr/actionBarSize"
        android:background="@color/colorPrimary"
        android:clickable="true"
        android:gravity="center_vertical">
    
    
    </RelativeLayout>
    
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true">
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/colorAccent"
            android:orientation="vertical"
            android:padding="2dp"
            >
            <!--Other views goes here without weight-->
    
        </LinearLayout>
    </ScrollView>
    </LinearLayout>