如何让按钮从android中的屏幕宽度填充50%?

Adh*_*ham 68 android

我想让按钮始终50%从屏幕的宽度填充,因为当我水平或垂直旋转设备时,总是从宽度填充按钮50%.

Rof*_*ion 180

这应该可以通过使用weightSum和layout_weight来实现:

<LinearLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_height="wrap_content"
 android:layout_width="fill_parent"
 android:orientation="horizontal"
 android:weightSum="1.0">
 <Button
  android:id="@+id/textbox3"
  android:layout_height="wrap_content"
  android:layout_weight=".5"
  android:layout_width="0dip"
  android:textSize="12sp" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)