我的问题很简单。我有布局:如何设置元素的宽度百分比?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="@drawable/mobile_background"
android:layout_width="fill_parent"
android:gravity="center"
android:layout_height="fill_parent"
>
<Button
android:text="GET MESSAGES"
android:
android:id="@+id/buttonMessages"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<Button
android:text="REGISTRATION"
android:id="@+id/buttonRegistration"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<Button
android:text="SETTINGS"
android:id="@+id/buttonSettings"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
但我需要设置非固定大小的按钮 - 我需要设置尺寸屏幕宽度的30%。我该怎么做?
还有什么意思呢? – user975290
您可以使用'findViewById'在您的活动中动态设置它们的宽度,但我认为xml方法并不令人头疼。 – Craigy