我正在 Android 上创建一个登录对话框,我希望两个按钮在顶部和底部边缘水平对齐,而不管屏幕尺寸如何。有时“忘记密码”会分两行,有时则不会。我不想在按钮上强加 minHeight
,并且更喜欢仅基于 XML 设计(而非代码)的解决方案。
风景很好:
纵向,默认实现使登录按钮比“忘记密码”短
我尝试的一个解决方案是为第一个按钮的 layout_height 参数设置 match_parent
。不太奏效:
XML:
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:id="@+id/terms_layout"
android:layout_marginTop="10dp"
>
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="@string/login"
android:textSize="18sp"
android:id="@+id/dialog_login_button_login"
/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/forgotPassword"
android:textSize="18sp"
android:id="@+id/dialog_login_button_forgot_password"
/>
</LinearLayout>
最佳答案
使用 RelativeLayout 并使“登录”按钮与“忘记密码”按钮的顶部和底部对齐
关于android - 如何确保按钮在此 Android 登录对话框中水平对齐?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31539331/