現在,我的登錄按鈕比我的應用程序名稱文本更寬,因爲它使用固定的相對佈局填充,但我希望它自動擴展到行與應用程序名稱文本的左邊緣和右邊緣對齊。有沒有什麼辦法以編程方式做到這一點?使按鈕寬度等於Android上的不同文本寬度(不是按鈕的文本)Android
我希望它在所有設備上看起來都一樣。我擔心,如果我只是硬編碼自己的頁邊空白,它會在我的設備上看起來很正確,但如果它們呈現不同的字體,可能無法在其他設備上正確顯示。
謝謝!
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>
樣機用紅色虛線說明我多麼希望應用程序名稱的兩側的我的登錄按鈕兩側排隊:
嘗試使用線性佈局 – Nabin 2014-08-28 01:46:32
這將如何使它們具有相同的寬度? – 2014-08-28 01:48:38
等待給你答案 – Nabin 2014-08-28 01:49:38