1

I have a Button with a custom android:background and an EditText above it (in a LinearLayout). I want the Button to take up about 30% of the available screen, with the EditText taking up the rest. I'm using layoutHowever, my custom image for my button needs the width to scaled at the same ratio as it's height, so it doesn't get stretched. How do I do that? So far I have:

<?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>

Thanks for any help,

Phil.

Phil Barr
  • 161
  • 1
  • 7

1 Answers1

0

A very similar question was asked, where the accepted solution was basically to layer the background behind your view with a FrameLayout. Less than ideal, but might be your only option: Android: Scale a Drawable or background image?

And this may be of no help at all- but you might explore what you can do with 9 patch drawable. A 9 patch drawable is basically a drawable (such as your background graphic) that has a special invisible border specifying if/where it will stretch. More info on 9 patch and the 9 patch tool.

Community
  • 1
  • 1
Nathan Fig
  • 14,970
  • 9
  • 43
  • 57