2016-07-14 40 views
-2

我不知道爲什麼,但我的佈局不可滾動。我想讓它滾動。iusse具有可滾動佈局

這是我的配置........................................... .................................................. ..

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@color/white" 
    android:gravity="center" 
    android:orientation="vertical" 
    android:padding="10dp" 
    android:fitsSystemWindows="true"> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:orientation="vertical" 
     android:paddingLeft="20dp" 
     android:paddingRight="20dp" > 
     <ImageView 
      android:background="@drawable/signor_pomidor" 
      android:layout_gravity="center_horizontal" 
      android:layout_width="150dp" 
      android:layout_height="150dp" /> 
     <EditText 
      android:id="@+id/email" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="10dp" 
      android:background="@color/btn_login_bg" 
      android:hint="@string/hint_email" 
      android:inputType="textEmailAddress" 
      android:padding="10dp" 
      android:singleLine="true" 
      android:textColor="@color/input_login" 
      android:textColorHint="@color/input_login_hint" /> 

     <EditText 
      android:id="@+id/password" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="10dp" 
      android:background="@color/btn_login_bg" 
      android:hint="@string/hint_password" 
      android:inputType="textPassword" 
      android:padding="10dp" 
      android:singleLine="true" 
      android:textColor="@color/input_login" 
      android:textColorHint="@color/input_login_hint" /> 

     <!-- Login Button --> 

     <Button 
      android:id="@+id/btnLogin" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="20dip" 
      android:background="@color/btn_login_bg" 
      android:text="@string/btn_login" 
      android:textColor="@color/btn_logut_bg" /> 

     <!-- Link to Login Screen --> 

     <Button 
      android:id="@+id/btnLinkToRegisterScreen" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="40dip" 
      android:background="@null" 
      android:text="@string/btn_link_to_register" 
      android:textAllCaps="false" 
      android:textColor="@color/btn_logut_bg" 
      android:textSize="15dp" /> 
    </LinearLayout> 

</ScrollView> 

截圖:

enter image description here

+2

您的佈局將滾動如果您的佈局內容超過屏幕高度。這很基本,所以請確保您的佈局內容超出屏幕高度。 –

+1

由於fill_parent已被棄用,請同時更改height和match_parent – Eenvincible

+1

我試過了你的代碼,它工作的很完美。此外,基於給定的照片,我猜你希望視圖在鍵盤出現時滾動,對嗎?請注意,我在API 22的模擬器上試了一下。你能告訴我們你測試了哪個版本嗎? –

回答

-1

的問題發生,因爲佈局的內容並不比屏幕更高。 ScrollView的要點是通過添加滾動功能允許更多的內容在同一個屏幕上。如果沒有可滾動的內容,這當然不起作用。

如果要滾動無論哪種方式,你有三種選擇:

  1. 設置了滾動本身的高度要大於內容

    • 設置了滾動的高度較小一個實例200dp
  2. 添加更多的內容

    • 這不需要描述;這一切都在標題
  3. 添加更多的利潤

    • 對於一個實例,添加fill_parent到最後一個按鈕。

雖然你更好,如果內容的組合高度屏幕內符合只是不使用滾動型。如果所有內容都適合屏幕內容,則不需要滾動,特別是因爲整個佈局專用於單一目的(佈局中登錄是一小部分,並且(按設計)佔用較少空間,所以需要ScrollViews。顯然,如果內容不同並佔用更多空間,則可能還需要ScrollView)。

另外,match_parent已棄用。改爲使用android:marginTop="400dp"

TL; DR:您不能滾動滾動型如果高度(垂直ScrollViews,寬度與水平的)的內容不會佔用更多的空間比屏幕

+0

不起作用... – pappa

+0

實際上是否需要滾動?你確定內容實際上超出了screen_嗎? – Zoe

+0

我複製並粘貼您的代碼...並且不起作用 – pappa