2013-03-28 58 views
1

我有這樣的佈局內的滾動視圖:的Android滾動視圖不滾動

<?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> 
  • 與滾動視圖顯示在最大尺寸的一部分並且不是滾動。

  • 末這兩個按鈕沒有顯示,他們顯然不適合在屏幕上。

我想使滾動工作,以便有按鈕出現。

爲什麼滾動佈局在最大尺寸的顯示被滾動呢?

會是什麼解決方案?

+0

我們能否擁有此佈局的屏幕截圖? – ChristopheCVB

回答

0

如果不滾動,因爲它的高度是wrap_content。

+0

我嘗試了每個參數的高度,它確實沒有改變。 – shuot

+0

嘗試設置一個任意100dip的高度只是爲了測試... – ChristopheCVB

2

爲了使按鈕出現在屏幕上,你應該有滾動內的按鈕了。大多數情況下,如果屏幕包含許多組件,則設計的屏幕應該具有父視圖作爲父視圖。 Main ScrollView - > LinearLayout/RelativeLayout - >根據需要添加組件。通過這樣做,您應該能夠看到按鈕。在這種方式下,即使您的佈局更改爲橫向,組件也不會隱藏,並且會顯示在滾動條中。希望你明白我的觀點,它可以幫助你解決你的問題。

就上面的代碼而言,由於按鈕不在滾動視圖中,所以您將無法看到按鈕,因此下面的視圖被隱藏。

0

由於ChristopheCVB說,你的滾動型需要不被wrap_content。 ScrollView只會滾動,如果它包含的內容較大(讀取較高的爲垂直ScrollView和較寬爲水平ScrollView)ScrollView本身。如果它較小,則不需要滾動。