Button Beyond An Background Image
i think i don't find the correct word for the title so i will try to explain correctly. So i have this image for a backround of my Layout : http://imageshack.us/photo/my-images/607
Solution 1:
From your question i understand that you want to avoid to put your buttons in your background image's left and right transparent edges. You can use the android:layout_marginLeft
and android:layout_marginRight
for this. For your code, something like this:
<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="vertical"android:background="@drawable/fond"
><ImageViewandroid:id="@+id/imageView1"android:contentDescription="@string/desc"android:layout_width="wrap_content"android:layout_height="wrap_content"android:src="@drawable/top"android:layout_gravity="top"android:adjustViewBounds="true"
/><LinearLayoutandroid:layout_below="@+id/imageView1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:orientation="vertical"android:background="@drawable/fond1"
><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_marginLeft="30dp" <!--Usethecorrectdpvalue, ijustuseitforexample-->
android:layout_marginRight="30dp" <!--Use the correct dp value, i just use it for example -->
android:weightSum="3"
>
<Buttonandroid:id="@+id/button_garçon"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/Bg"android:background="@drawable/button_purple"android:layout_weight="1"android:textColor="#ffffff"android:onClick="actionGarçon"
/><Buttonandroid:id="@+id/button_mixte"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/Bm"android:background="@drawable/button_purple"android:layout_weight="1"android:textColor="#ffffff"android:onClick="actionMixte"
/><Buttonandroid:id="@+id/button_fille"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/Bf"android:background="@drawable/button_purple"android:layout_weight="1"android:textColor="#ffffff"android:onClick="actionFille"
/></LinearLayout></LinearLayout></LinearLayout>
Solution 2:
If you are using a LinearLayout
you can set the background to your image. Then you can put anything inside the LinearLayout
and everything will fit correctly inside your image.
For example:
<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent"android:background="#ffffff"android:orientation="vertical"><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="320dp"android:layout_height="512dp"android:background="@drawable/scaled"android:orientation="vertical" ><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="25dp"android:text="Button" /></LinearLayout>
Hope that helps.
Solution 3:
This is a symplify part of my code :
<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="vertical"android:background="@drawable/fond"
><ImageViewandroid:id="@+id/imageView1"android:contentDescription="@string/desc"android:layout_width="wrap_content"android:layout_height="wrap_content"android:src="@drawable/top"android:layout_gravity="top"android:adjustViewBounds="true"
/><LinearLayoutandroid:layout_below="@+id/imageView1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:orientation="vertical"android:background="@drawable/fond1"
><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="wrap_content"android:weightSum="3"
><Buttonandroid:id="@+id/button_garçon"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/Bg"android:background="@drawable/button_purple"android:layout_weight="1"android:textColor="#ffffff"android:onClick="actionGarçon"
/><Buttonandroid:id="@+id/button_mixte"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/Bm"android:background="@drawable/button_purple"android:layout_weight="1"android:textColor="#ffffff"android:onClick="actionMixte"
/><Buttonandroid:id="@+id/button_fille"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/Bf"android:background="@drawable/button_purple"android:layout_weight="1"android:textColor="#ffffff"android:onClick="actionFille"
/></LinearLayout></LinearLayout></LinearLayout>
Post a Comment for "Button Beyond An Background Image"