【发布时间】:2014-08-28 10:38:17
【问题描述】:
现在我的登录按钮比我的应用名称文本更宽,因为它使用相对布局的固定填充,但我希望它自动加宽以与应用名称文本的左右边缘对齐。有没有办法以编程方式做到这一点?
我希望它在所有设备上看起来都一样。恐怕如果我只是对自己的边距进行硬编码,它在我的设备上看起来会是正确的,但如果它们以不同的方式呈现字体,则在其他设备上可能看起来不正确。
谢谢!
layout.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:background="@drawable/back_image"
android:padding="20dp" >
<TextView
android:id="@+id/AppNameTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="@dimen/margin_top"
android:fontFamily="Arial"
android:text="@string/app_title"
android:textColor="@color/white"
android:textSize="@dimen/text_size" />
<com.timey.widget.Button
android:id="@+id/signInButton"
android:layout_width="match_parent"
android:layout_height="65dp"
android:background="@color/green"
android:fontFamily="Arial"
android:text="@string/sign_in"
android:textColor="@color/white"
android:textSize="30sp" />
</RelativeLayout>
带有红色虚线的样机说明我希望应用名称的两侧与登录按钮的两侧对齐:
【问题讨论】:
-
尝试使用线性布局
-
如何使它们具有相同的宽度?
-
等着给你答案
标签: android