我試圖創建一個帶有EditText的登錄屏幕,您可以在其中輸入一個電子郵件,一個TextView,當您忘記密碼時可以按下,一個按鈕可以進入下一步在登錄過程中。layout_above與layout_alignParentBottom無法正常工作
我在XML當前的實現是基於登錄屏幕,你可以在ADT自動生成的示例代碼:
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".LoginActivity" >
<!-- Login progress -->
<LinearLayout
android:id="@+id/login_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center_horizontal"
android:orientation="vertical"
android:visibility="gone" >
<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp" />
<TextView
android:id="@+id/login_status_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:fontFamily="sans-serif-light"
android:text="@string/login_progress_signing_in"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<!-- Login form -->
<ScrollView
android:id="@+id/login_form"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
style="@style/LoginFormContainer"
android:layout_gravity="center"
android:layout_centerInParent="true"
android:layout_width="250dp"
android:layout_height="350dp"
android:background="@drawable/shop_background"
android:paddingLeft="16dp"
android:paddingRight="16dp">
<EditText
android:id="@+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/prompt_email"
android:inputType="textEmailAddress"
android:maxLines="1"
android:singleLine="true" />
<TextView
android:text="Forgot password"
android:layout_above="@id/sign_in_button"
android:id="@+id/forgot_password"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="@+id/sign_in_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:paddingLeft="32dp"
android:paddingRight="32dp"
android:background="@drawable/button_login"
android:textColor="@android:color/white"
android:text="@string/action_sign_in_register"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
</ScrollView>
</merge>
的MergeLayout的第一部分顯示this當登錄嘗試正在進行中。 MergeLayout的第二部分ScrollLayout顯示爲this。
我已經創建並在xml文檔中的TextView不會顯示在最後一個屏幕上。在Android Studio的preview中,您還可以看到它位於錯誤的地方。
將layout_above
更改爲layout_below
導致this預覽。所以看起來好像TextView認爲Button仍然在頂部而不是底部。
我在/ r/androiddev得到的一個建議是改變RelativeLayout中視圖的順序,使得TextView位於底部,並且在此之前聲明所有其他視圖。不幸的是,這並沒有幫助。
那麼,是否只是我做錯了什麼,或者我應該用另一種方式來獲取按鈕上方的文本?
謝謝你,是解決問題的位置。不知道爲什麼我沒有想到這一點。雖然我仍然很好奇爲什麼原始版本正在被竊聽。 – fdorssers
有時它不能正常工作...我也不知道爲什麼這不起作用。 –