Attached is a sample OK button screen shot seen on the UI
The left one is created using XML as follows
<Button android:id="@+id/btnAddPlaylistOK"
            android:layout_height="wrap_content"
            android:text="OK" android:layout_gravity="center_horizontal"
            android:textColor="@color/white" android:textStyle="bold"
            android:typeface="normal" android:clickable="true"
android:background="@drawable/button_style"
             android:drawableLeft="@drawable/button_left_style"
            android:drawableRight="@drawable/button_right_style"
android:gravity="center_vertical|center_horizontal|center"
            android:layout_width="55px" android:layout_marginTop="10dip"
            android:layout_marginLeft="30dip">

And in drawable ,*

button_style.xml
*<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android";>
    <item android:drawable="@drawable/btns_mid_up_320x480" />
</selector>*

button_left_style.xml*

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android";>

    <item android:drawable="@drawable/btns_lft_up_320x480" />
</selector>

<?xml version="1.0" encoding="utf-8"?>
    <item android:drawable="@drawable/btns_rt_up_320x480" />
</selector>

*button_right_style.xml*
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android";>
    <item android:drawable="@drawable/btns_rt_up_320x480" />
</selector>


Now insead of using the style in xml , i am trying to do that in code.
The defination of Button is same in the XML except the
android:background="@drawable/button_style"
             android:drawableLeft="@drawable/button_left_style"
            android:drawableRight="@drawable/button_right_style" have been
removed and inseat , i have done the following in code .
btn.setBackgroundDrawable(getResources().getDrawable(
                R.drawable.btns_mid_up_320x480));

btn.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(
                R.drawable.btns_lft_up_320x480), null, getResources()
                .getDrawable(R.drawable.btns_rt_up_320x480), null);
The right image in the attached screen shot shows that everything is
distored.
I tried adjusting the layout_width, layout_heighyt , but its not working..
Thanks,
Alok


On Mon, Apr 19, 2010 at 4:29 PM, Alok Kulkarni <kulsu...@gmail.com> wrote:

> Hi,
> Can i do this :-
> Set the image background path as package:imageName
> Example.. At runtime , my package is com.test.android .Inside that i have
> an image whose path i want to mention in the XML layout file as
> android:src = com.test.android/img1 for an ImageButton.
> I saw an SDK reference for ImageView as android:src =
> @[+][package:]type:name .. But i am not getting how to use it.. I think it
> must not be possibe , but if there is any way , please specify..
> The reason why i want to do this is that , when i specify a drawable at
> runtime for my image buttons, i change the images according to Focus
> received , or onKeyup, KeyDown.. but its not working as expected.When i
> mention the same thing as style under drawable , it works fine. So if my
> theme is going to change at runtime , i want to set the drawable at runtime
> , keepnig the path same in the xml.
> Thanks ,
> Alok
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

<<attachment: Ok btn.JPG>>

Reply via email to