我在TextInputLayout中包含了一個EditText。我希望在EditText下顯示錯誤,但是與屏幕的右端對齊。TextInputLayout錯誤對齊
我的XML是這樣的:
<android.support.design.widget.TextInputLayout
android:id="@+id/text_input_email"
style="@style/forgot_pass_text_inputlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/tv_enter_email_message"
android:layout_marginTop="@dimen/email_padding_top"
android:hintTextAppearance="@{forgotPasswordVM.hintTextAppearance}"
android:theme="@style/forgot_pass_til_state"
app:error="@{forgotPasswordVM.email.textInputError}">
<EditText
android:id="@+id/actv_email"
style="@style/forgot_pass_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/email_address"
android:imeActionId="@+id/btn_submit"
android:imeOptions="actionSend"
android:inputType="textEmailAddress"
android:maxLines="1"
android:onEditorAction="@{forgotPasswordVM.onEditorAction}"
android:singleLine="true"
app:binding="@{forgotPasswordVM.email.text}" />
</android.support.design.widget.TextInputLayout>
我是使用數據綁定。
我已經試過上都的EditText和TextInputLayout設置android:gravity="right"
和android:layout_gravity="right"
。它們都不以我想要的方式工作。
我已經嘗試在主題中設置權重以及樣式。對錯誤也沒有任何影響。
我已經嘗試了在app:errorTextAppearance="@style/right_error"
內應用的風格的權重。即使這不起作用。
我試圖編程方式通過使用一SpannableStringBuilder具有以下this link一個AlignmentSpan移位錯誤到右側。即使這對我不起作用。
我不知道還有什麼可以嘗試的。請建議。
您可以嘗試使用[我的答案](http://stackoverflow.com/a/40706872)中的某個選項來獲取錯誤「TextView」,並在其上調用setGravity(Gravity.RIGHT) 。我沒有測試過,但是IIRC,錯誤「TextView」有一個'match_parent'寬度,所以它應該按照你描述的那樣對齊它的文本。 –