Android 使用布局权重时保持视图对象的比例
我有一个带有自定义android:background的按钮,上面有一个EditText(线性布局)。我希望按钮占据大约30%的可用屏幕,编辑文本占据其余部分。我使用的是LayouthOver,我的按钮自定义图像需要以与高度相同的比例缩放宽度,因此不会拉伸。我该怎么做? 到目前为止,我已经:Android 使用布局权重时保持视图对象的比例,android,layout,Android,Layout,我有一个带有自定义android:background的按钮,上面有一个EditText(线性布局)。我希望按钮占据大约30%的可用屏幕,编辑文本占据其余部分。我使用的是LayouthOver,我的按钮自定义图像需要以与高度相同的比例缩放宽度,因此不会拉伸。我该怎么做? 到目前为止,我已经: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/woodbackground">
<EditText
android:id="@+id/editText1"
android:layout_height="0dip"
android:layout_weight="2"
android:layout_width="fill_parent"
android:layout_margin="10dip">
</EditText>
<Button
android:layout_height="0dip"
android:background="@drawable/sayit_button"
android:layout_width="wrap_content"
android:id="@+id/button1"
android:layout_weight="1"
android:layout_gravity="center">
</Button>
</LinearLayout>
谢谢你的帮助
Phil.有人问了一个非常类似的问题,公认的解决方案基本上是在视图后面用框架布局分层背景。不太理想,但可能是您唯一的选择: 这可能毫无帮助,但您可能会探索使用9 patch drawable可以做什么。9面片可绘制基本上是可绘制的(例如背景图形),它有一个特殊的不可见边框,指定它是否会拉伸/拉伸到哪里。越来越多