Android scrollview不支持滚动



我有这样的布局,里面有一个scrollview:

<?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/tools"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:orientation="vertical" 
     android:background="#eeeeee">
     <!-- HEADER -->
     <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:orientation="vertical" >
         <LinearLayout
             android:layout_width="match_parent"
             android:layout_height="1dp"
             android:background="#ffffff"
             android:orientation="vertical" >        
         </LinearLayout>
         <LinearLayout
             android:layout_width="match_parent"
             android:layout_height="1dp"
             android:background="#868686"
             android:orientation="vertical" >        
         </LinearLayout>
         <RelativeLayout
             android:id="@+id/parent_linear"
             android:layout_width="fill_parent"
             android:layout_height="50dp"
             android:background="@drawable/gradient_header" >
             <TextView
                 android:id="@+id/textView1"
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content"
                 android:layout_centerHorizontal="true"
                 android:layout_centerInParent="true"
                 android:layout_centerVertical="true"
                 android:layout_marginBottom="@dimen/margin_normal"
                 android:layout_marginTop="@dimen/margin_small"
                 android:gravity="center_horizontal"
                 android:text="@string/proposed_plan_prompt"
                 android:textColor="#797A77"
                 android:textSize="15sp"
                 android:textStyle="bold" />
         </RelativeLayout>
         <LinearLayout
             android:layout_width="match_parent"
             android:layout_height="2dp"
             android:background="#C7C7C7"
             android:orientation="vertical" >        
         </LinearLayout>
         <LinearLayout
             android:layout_width="match_parent"
             android:layout_height="3dp"
             android:background="@drawable/gradient_header_separator" 
             android:orientation="vertical" >        
         </LinearLayout>
     </LinearLayout>
     <!-- BODY -->
     <!-- Proposed plan (summary) -->
     <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_marginTop="@dimen/margin_normal"
         android:layout_marginLeft="@dimen/margin_normal"
         android:layout_marginRight="@dimen/margin_normal"
         android:background="@drawable/border"
         android:orientation="horizontal" >
         <LinearLayout
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:layout_weight="1"
             android:layout_marginLeft="@dimen/margin_small"
             android:layout_marginRight="@dimen/margin_small"
             android:orientation="vertical" >
             <TextView
                android:id="@+id/providerNameView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" 
                android:layout_marginTop="2dp"
                android:text="ABCD"
                android:textSize="25sp"
                android:textStyle="bold" />         
             <TextView
                android:id="@+id/planView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="2dp"
                android:text="1234"
                android:textSize="12sp"
                android:textColor="#737373"/>
         </LinearLayout>
         <View
            android:id="@+id/separator" 
            android:layout_width="1dip"
            android:layout_height="50dp"
            android:layout_marginTop="@dimen/margin_small"
            android:background="@drawable/gradient_vertical" />
         <LinearLayout
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:layout_weight="1"
             android:layout_alignParentRight="true"
             android:layout_marginLeft="@dimen/margin_small"
             android:layout_marginRight="@dimen/margin_small"
             android:orientation="vertical" >
             <LinearLayout
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:layout_alignParentRight="true"
                 android:layout_gravity="right"
                 android:layout_marginLeft="@dimen/margin_small"
                 android:layout_marginRight="@dimen/margin_small"
                 android:gravity="top"
                 android:orientation="horizontal" >
                 <TextView
                    android:id="@+id/priceView"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" 
                    android:text="XY"
                    android:textSize="32sp"
                    android:textStyle="bold" />
                 <TextView
                    android:id="@+id/textView3"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent" 
                    android:text="+123"
                    android:textColor="#565756"
                    android:textSize="12sp" />
             </LinearLayout>
             <TextView
                 android:id="@+id/totPriceView"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:layout_gravity="right"
                 android:text="(information)"
                 android:textColor="#737373"
                 android:textSize="12sp" />
         </LinearLayout>
     </LinearLayout>
     <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_marginBottom="@dimen/margin_normal"
         android:layout_marginLeft="@dimen/margin_normal"
         android:layout_marginRight="@dimen/margin_small"
         android:layout_marginTop="@dimen/margin_normal"
         android:orientation="vertical" >
         <TextView
             android:id="@+id/detailsTextView"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:text="Choose:"
             android:textSize="12sp"
             android:textStyle="bold" />
         <SeekBar
             android:id="@+id/seekBar1"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:layout_weight="1" />
         <TextView
             android:id="@+id/detailsTextView"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:layout_marginLeft="@dimen/margin_small"
             android:text="Best"
             android:textColor="#737373"
             android:textSize="12sp" />
     </LinearLayout>
     <TextView
         android:id="@+id/detailsTextView"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_marginLeft="@dimen/margin_normal"
         android:text="Details:"
         android:textSize="12sp"
         android:textStyle="bold" />
     <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_marginBottom="@dimen/margin_normal"
         android:layout_marginLeft="@dimen/margin_normal"
         android:layout_marginRight="@dimen/margin_small"
         android:layout_marginTop="@dimen/margin_small"
         android:background="@drawable/border"
         android:orientation="vertical" >
         <FrameLayout
             android:layout_width="match_parent"
             android:layout_height="wrap_content" >
             <ScrollView
                 android:id="@+id/scrollView1"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content" >
                 <LinearLayout
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
                     android:layout_gravity="right"
                     android:layout_marginLeft="90dp"
                     android:layout_marginRight="@dimen/margin_small"
                     android:background="@drawable/border"
                     android:orientation="vertical" >
                     <RelativeLayout
                         android:id="@+id/line1Layout"
                         android:layout_width="match_parent"
                         android:layout_height="30sp"
                         android:background="#ffffff"
                         android:gravity="center_vertical"
                         android:orientation="horizontal" >
                         <TextView
                             android:id="@+id/line1Title"
                             android:layout_width="wrap_content"
                             android:layout_height="wrap_content"
                             android:textSize="@dimen/font_normal" />
                         <TextView
                             android:id="@+id/line1Text"
                             android:layout_width="wrap_content"
                             android:layout_height="wrap_content"
                             android:layout_alignParentRight="true"
                             android:background="@drawable/border_attribute"
                             android:textSize="@dimen/font_normal"
                             android:visibility="invisible" />
                     </RelativeLayout>
                     <RelativeLayout
                         android:id="@+id/line2Layout"
                         android:layout_width="match_parent"
                         android:layout_height="30sp"
                         android:background="#EAEAEA"
                         android:gravity="center_vertical"
                         android:orientation="horizontal" >
                         <TextView
                             android:id="@+id/line2Title"
                             android:layout_width="wrap_content"
                             android:layout_height="wrap_content"
                             android:textSize="@dimen/font_normal" />
                         <TextView
                             android:id="@+id/line2Text"
                             android:layout_width="wrap_content"
                             android:layout_height="wrap_content"
                             android:layout_alignParentRight="true"
                             android:background="@drawable/border_attribute"
                             android:textSize="@dimen/font_normal"
                             android:visibility="invisible" />
                     </RelativeLayout>
                     <RelativeLayout
                         android:id="@+id/line3Layout"
                         android:layout_width="match_parent"
                         android:layout_height="30sp"
                         android:background="#ffffff"
                         android:gravity="center_vertical"
                         android:orientation="horizontal" >
                         <TextView
                             android:id="@+id/line3Title"
                             android:layout_width="wrap_content"
                             android:layout_height="wrap_content"
                             android:textSize="@dimen/font_normal" />
                         <TextView
                             android:id="@+id/line3Text"
                             android:layout_width="wrap_content"
                             android:layout_height="wrap_content"
                             android:layout_alignParentRight="true"
                             android:background="@drawable/border_attribute"
                             android:textSize="@dimen/font_normal"
                             android:visibility="invisible" />
                     </RelativeLayout>
                     <RelativeLayout
                         android:id="@+id/line4Layout"
                         android:layout_width="match_parent"
                         android:layout_height="30sp"
                         android:background="#EAEAEA"
                         android:gravity="center_vertical"
                         android:orientation="horizontal" >
                         <TextView
                             android:id="@+id/line4Title"
                             android:layout_width="wrap_content"
                             android:layout_height="wrap_content"
                             android:textSize="@dimen/font_normal" />
                         <TextView
                             android:id="@+id/line4Text"
                             android:layout_width="wrap_content"
                             android:layout_height="wrap_content"
                             android:layout_alignParentRight="true"
                             android:background="@drawable/border_attribute"
                             android:textSize="@dimen/font_normal"
                             android:visibility="invisible" />
                     </RelativeLayout>
                     <RelativeLayout
                         android:id="@+id/line5Layout"
                         android:layout_width="match_parent"
                         android:layout_height="30sp"
                         android:background="#ffffff"
                         android:gravity="center_vertical"
                         android:orientation="horizontal" >
                         <TextView
                             android:id="@+id/line5Title"
                             android:layout_width="wrap_content"
                             android:layout_height="wrap_content"
                             android:textSize="@dimen/font_normal" />
                         <TextView
                             android:id="@+id/line5Text"
                             android:layout_width="wrap_content"
                             android:layout_height="wrap_content"
                             android:layout_alignParentRight="true"
                             android:background="@drawable/border_attribute"
                             android:textSize="@dimen/font_normal"
                             android:visibility="invisible" />
                     </RelativeLayout>
                     <RelativeLayout
                         android:id="@+id/line6Layout"
                         android:layout_width="match_parent"
                         android:layout_height="30sp"
                         android:background="#EAEAEA"
                         android:gravity="center_vertical"
                         android:orientation="horizontal" >
                         <TextView
                             android:id="@+id/line6Title"
                             android:layout_width="wrap_content"
                             android:layout_height="wrap_content"
                             android:textSize="@dimen/font_normal" />
                         <TextView
                             android:id="@+id/line6Text"
                             android:layout_width="wrap_content"
                             android:layout_height="wrap_content"
                             android:layout_alignParentRight="true"
                             android:background="@drawable/border_attribute"
                             android:textSize="@dimen/font_normal"
                             android:visibility="invisible" />
                     </RelativeLayout>
                 </LinearLayout>
             </ScrollView>
             <ImageView
                 android:id="@+id/imageView1"
                 android:layout_width="100dp"
                 android:layout_height="140dp"
                 android:layout_gravity="left|center_vertical"
                 android:src="@drawable/robin4" />
         </FrameLayout>
         <Button
             android:id="@+id/button_proposed_extras"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:layout_marginBottom="@dimen/margin_small"
             android:layout_marginLeft="20dp"
             android:layout_marginRight="20dp"
             android:layout_marginTop="@dimen/margin_normal"
             android:background="@drawable/button_transparent"
             android:text="@string/extras_title"
             android:textColor="#298A17"
             android:textStyle="bold|italic"
             android:visibility="invisible" />
     </LinearLayout>
      <Button
         android:id="@+id/button_proposed_change"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_marginTop="@dimen/margin_normal"
         android:layout_marginLeft="20dp"
         android:layout_marginRight="20dp"
         android:background="@drawable/button"
         android:text="@string/proposition_change_title"
         android:textColor="#ffffff"
         android:textStyle="bold" />
     <Button
         android:id="@+id/button_proposed_no_change"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_marginTop="@dimen/margin_normal"
         android:layout_marginLeft="20dp"
         android:layout_marginRight="20dp"
         android:background="@drawable/button_silver"
         android:text="@string/proposition_no_change_title"
         android:textColor="#298A17"
         android:textStyle="bold" /> 

 </LinearLayout>
  • 具有滚动视图的部分以最大尺寸显示,并且不滚动。

  • 最后的两个按钮没有显示,它们显然不适合屏幕

我想有滚动工作,以便有按钮出现。

为什么滚动布局显示在最大尺寸,而不是滚动?

解决方案是什么?

为了使按钮出现在屏幕上,您应该在滚动框中也有按钮。大多数情况下,如果屏幕包含许多组件,那么您设计的屏幕应该将scrollview作为父屏幕。主ScrollView -> LinearLayout/RelativeLayout ->根据需要添加组件。通过这样做,您也应该能够看到按钮。这样做,即使你的布局改变为横向,组件也不会被隐藏,而是会显示在滚动条中。希望你明白我的意思,并帮助你解决你的问题。

就上面的代码而言,您将无法看到按钮,因为按钮不在scrollview中,因此下面的视图是隐藏的。

不滚动,因为它的高度是wrap_content

正如ChristopheCVB所说,你的ScrollView不需要是wrap_content。只有当ScrollView所包含的内容比ScrollView本身大(垂直ScrollView为,水平ScrollView为)时,ScrollView才会滚动。