2010-08-03 76 views
8

我想實現一些地方和EditTexts標誌在底部顯示在屏幕上有按鈕欄登錄來看,是這樣的:Android的滾動型中的RelativeLayout與按鈕欄

alt text http://russellhaering.com/media/addAccount.png

的問題在於,在非常小的屏幕上,特別是當它們側向旋轉時,整個主視圖不適合屏幕。

我現在有

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="#234C59" > 
    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:paddingTop="5dip" 
     android:paddingLeft="15dip" 
     android:paddingRight="15dip" 
     android:orientation="vertical" > 
     <ImageView 
      android:id="@+id/logo" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:scaleType="fitCenter" 
      android:layout_centerHorizontal="true" 
      android:src="@drawable/logo" /> 
     <EditText 
      android:id="@+id/input_email" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="10dip" 
      android:inputType="textEmailAddress" 
      android:singleLine="true" 
      android:hint="Username or email" /> 
     <EditText 
      android:id="@+id/input_password" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="" 
      android:inputType="textPassword" 
      android:singleLine="true" 
      android:hint="Password" /> 
    </LinearLayout> 
    <LinearLayout 
     android:id="@+id/buttonbar_login" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:orientation="horizontal" 
     style="@android:style/ButtonBar" > 
     <Button 
      android:id="@+id/button_signup" 
      android:layout_width="0dip" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="Sign Up" /> 
     <Button 
      android:id="@+id/button_login" 
      android:layout_width="0dip" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="Log In" /> 
    </LinearLayout> 
</RelativeLayout> 

我試圖封裝在一個滾動型,看起來像這樣的第一LinnearLayout:

<ScrollView 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
      <!-- Linear Layout Here --> 
</ScrollView> 

但是,引入了兩個問題:

  1. 即使在數據不全都適合的屏幕上,ScrollView也不會滾動

  2. ButtonBar漂浮在屏幕鍵盤的上方,當鍵盤出現時屏幕更加模糊。

當我在ScrollView中有按鈕時,一切正常,但現在我在ButtonBar中有它們,我很難解決這個問題。

回答

15

原來的解決方案需要兩個步驟:

  1. 無力滾動是滾動型作爲按鈕欄後面的結果。爲了解決這個問題,我在按鈕欄下面定義了ScrollView,然後使用android:layout_above="@id/buttonbar_login"強制ScrollView完全駐留在按鈕欄之上。

  2. 顯然,當屏幕鍵盤被打開時,如果您有一個ScrollView,它將被調整大小,允許按鈕欄隨鍵盤浮起來。爲了解決這個問題,我修改了清單並添加了android:windowSoftInputMode =「adjustPan」來防止ScrollView的大小。

0

如果您的用例支持隱藏橫向按鈕欄,您可以檢查Resources.getSystem().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE並將按鈕欄設置爲View.GONE

您也可能需要在清單文件中的<activity>上設置android:windowSoftInputMode="adjustResize"。當根佈局是ScrollView(iirc)時,Android將僅自動將其放入adjustResize

+0

不幸的是,我需要保持橫向可見的按鈕欄,因爲你需要酒吧提交表單(我不希望有人在G1或任何有關閉鍵盤和旋轉電話提交)。 好消息是,您對android的建議:windowSoftInputMode =「adjustResize」讓我走上了正確的軌道,我能夠解決它。我會暫時發佈我的答案。 感謝您的幫助! – 2010-08-03 04:39:09