我有一个带有自定义android的背景:背景和它上面的EditText(在LinearLayout中)。我希望Button占据可用屏幕的大约30%,EditText占用剩下的部分。我正在使用布局但是,我的按钮的自定义图像需要以与其高度相同的比例缩放宽度,因此它不会被拉伸。我怎么做? 到目前为止,我有:
<?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>
感谢您的帮助,
菲尔。
答案 0 :(得分:0)
提出了一个非常类似的问题,其中接受的解决方案基本上是使用FrameLayout将视图背后的背景分层。不太理想,但可能是您唯一的选择:Android: Scale a Drawable or background image?
这可能根本没有任何帮助 - 但是你可能会探索你可以用9补丁绘制你可以做些什么。一个9补丁drawable基本上是一个drawable(如你的背景图形),它有一个特殊的不可见边框,指定它将拉伸的位置。更多info on 9 patch和9 patch tool。