0

i design a Button combine between image.png and text . i have been searching but still can't get like what i want.

for selector :

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape
            android:shape="rectangle">
            <!--apply button background transparent, full opacity-->
            <solid
                android:color="#00ffffff" />
            <!--make button border solid color, nontransparent-->
            <stroke
                android:color="#ffffff"
                android:width="2dp"/>
            <corners
                android:radius="2dp"
                android:bottomLeftRadius="1dp"
                android:bottomRightRadius="1dp"
                android:topLeftRadius="1dp"
                android:topRightRadius="1dp"
                />
            <padding
                android:left="5dp"
                android:right="5dp"
                />
        </shape>
    </item>
</selector>

for button.xml

<Button

            android:layout_width="350dp"
            android:layout_height="60dp"
            android:layout_gravity="center"
            android:text="Guest"
            android:textAllCaps="false"
            android:textColor="@android:color/white"
            android:textStyle="bold"
            android:textSize="20sp"
            android:gravity="left|center_vertical"
            android:paddingLeft="20dp"
            android:drawableRight="@drawable/ico_arrow_white_xhdpi"
         android:background="@drawable/button_guest_register_login_border"/>

this image that i want to resize :

enter image description here

Thank in advance

Sen
  • 154
  • 1
  • 11
  • You can use android:drawablePadding attribute and set the padding of right drawable image – Hashir Sheikh Oct 01 '15 at 04:26
  • @AndiGeeky : sorry, i mean, like what i want to design in my apps (maybe my grammar made you misunderstand ) – Sen Oct 01 '15 at 04:31
  • @Hashir Sheikh : can't worked. Would you mind to explain more? – Sen Oct 01 '15 at 04:39
  • Opps, sorry! my mistake this attribute help u to set position of cross image. This link help you to resize ur image : http://stackoverflow.com/questions/10623906/scale-drawableleft-in-button-with-text – Hashir Sheikh Oct 01 '15 at 04:50
  • @Hashir Sheikh : okay thanks! but, is this working for `.png` extension ? sorry! i haven't try using like this before. – Sen Oct 01 '15 at 05:01
  • Yes , this will work for png extention, You can retrive the bitmap from drawable folder using BitmapFactory.decodeResources(getResources(),R.drawable.test.png) – Hashir Sheikh Oct 01 '15 at 05:05
  • Also you have to set drawable right from programmatically, see this link for this point http://stackoverflow.com/questions/4502605/how-to-programatically-set-drawableleft-on-android-button – Hashir Sheikh Oct 01 '15 at 05:06
  • @HashirSheikh : Thanks a lot! other inspiration for me ^^.. – Sen Oct 01 '15 at 05:34

1 Answers1

0

Instead of button you can use this and implement click event of framelayout.

   <FrameLayout 
         android:id="@+id/button"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"                
         android:background="<Your Background image>">

            <TextView
                android:id="@+id/text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:text="<Your text>"                   
                android:textSize="18sp" />

            <ImageView
                android:id="@+id/image"
                android:layout_width="20dp"
                android:layout_height="20dp"
                android:layout_gravity="right|center"
                android:layout_marginRight="10dp"
                android:gravity="center|right"
                android:src="<image drawable>" />
        </FrameLayout>
Mayuri Joshi
  • 164
  • 1
  • 2
  • 12
  • thanks a lot!! I have one solution now, but i still prefer to use on `Button` – Sen Oct 01 '15 at 04:53
  • Try this :- Drawable drawable = getResources().getDrawable(R.drawable.s_vit); drawable.setBounds(0, 0, (int)(drawable.getIntrinsicWidth()*0.5), (int)(drawable.getIntrinsicHeight()*0.5)); ScaleDrawable sd = new ScaleDrawable(drawable, 0, scaleWidth, scaleHeight); Button btn = findViewbyId(R.id.yourbtnID); btn.setCompoundDrawables(sd.getDrawable(), null, null, null); – Mayuri Joshi Oct 01 '15 at 06:09
  • why when i clicked the FrameLayout there is no response like Button (when you click)? – Sen Oct 01 '15 at 09:35
  • Which type of response can you specify? – Mayuri Joshi Oct 01 '15 at 10:08