我已使用layout_weight
参数将按钮的宽度设置为总布局宽度的70%,但似乎我错过了一些重要的细节以使其工作。使用重量的按钮宽度的Android相对布局
(另一种解决办法是用编程方式来display.getWidth()
工作,但它也不管用,因为我不知道我的.xml应该是什么样子如果我选择设定button.setWidth()
宽度)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_weight="1.0">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="15px"
android:id="@+id/userVersionTextViewNew"
android:gravity="center"
android:layout_centerVertical="true"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="15px"
android:gravity="center"
android:layout_above="@id/userVersionTextViewNew"
android:id="@+id/userSoftSerialNumberTextView"/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/logo_200"
android:layout_above="@id/userSoftSerialNumberTextView"
android:layout_centerHorizontal="true"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="15px"
android:gravity="center"
android:layout_below="@id/userVersionTextViewNew"
android:id="@+id/dummyTextView"/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/loginButton"
android:text="Σύνδεση"
android:layout_centerHorizontal="true"
android:layout_below="@id/dummyTextView"
android:layout_weight="0.7"/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/demoLoginButton"
android:text="Δοκιμαστική χρήση"
android:layout_centerHorizontal="true"
android:layout_below="@id/loginButton"
android:layout_weight="0.7"/>
</RelativeLayout>
看起来像这样可以帮助你:http://stackoverflow.com/questions/4961355/percentage-width-in-a-relativelayout – birdy
在一面注意它不建议使用px与文本大小,而不是使用sp – Ahmed
@艾哈迈德谢谢你。我会牢记这一点! :) – iCantSeeSharp