how do I make an image fit in my button - android

each time I add and image to my button (want to add it below the text) it only shows the top left of the image and adds itself at the top of the button even when I use android:drawableBottom .
here is my XML code :
<Button
android:layout_width="162dp"
android:layout_height="200dp"
android:text="#string/weather_station"
android:textStyle="bold"
android:textSize="18dp"
android:background="#drawable/weather"
android:paddingBottom="120dp"
android:paddingLeft="5dp"
android:typeface="monospace"
android:id="#+id/weather_station" />
android:drawableBottom="#drawable/weatherman"
/>

use ImageButton instead of using Button and try to scale the image`
<ImageButton
android:id="#+id/my_image_button"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:src="#drawable/my_img" />

<Button
android:layout_width="162dp"
android:layout_height="200dp"
android:text="bUTTON"
android:textStyle="bold"
android:textSize="18dp"
android:background="#drawable/shape1"
android:paddingBottom="120dp"
android:paddingLeft="5dp"
android:drawableBottom="#drawable/cast_ic_notification_2"
android:typeface="monospace"
android:id="#+id/weather_station" />
how cant it possible even your drawable line out of scop ? try above WORKING CODE

Try setting up the below scale type in the xml for fill image in button.
android:scaleType="scaleXY"
So put this attribute in your xml code.
<Button
android:layout_width="162dp"
android:layout_height="200dp"
android:text="#string/weather_station"
android:textStyle="bold"
android:textSize="18dp"
android:background="#drawable/weather"
android:paddingBottom="120dp"
android:scaleType="scaleXY"
android:paddingLeft="5dp"
android:typeface="monospace"
android:id="#+id/weather_station"
android:drawableBottom="#drawable/weatherman"/>

Related

Auto resize Textview

My goal is to create Auto rotate textView.Here is my xml code
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
<TextView
android:id="#+id/u_major_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="#dimen/u_common_margin_left"
android:maxLines="1"
android:paddingRight="#dimen/u_common_margin_left"
android:singleLine="true"
android:text="0.00"
android:autoSizeTextType="uniform"
android:autoSizeMinTextSize="12dp"
android:autoSizeMaxTextSize="70dp"
android:autoSizeStepGranularity="2dp"
android:textColor="#000000"
android:textSize="70dp"
/>
<TextView
android:id="#+id/u_minor_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/u_major_text"
android:layout_marginLeft="-12dp"
android:layout_marginTop="7dp"
android:layout_toEndOf="#+id/u_major_text"
android:layout_toRightOf="#+id/u_major_text"
android:gravity="center"
android:singleLine="true"
android:text="₾"
android:textColor="#000000"
android:textSize="30dp" />
</RelativeLayout>
my goal is to my minor_textview can to be auto resize function.first time text size is 70dp but I want to decrease size depends on a text. What am I doing wrong ?
Apparently, since Android 8.0 and below (thanks to the Support Library) you can use an attribute to auto resize your Textview:
TextView minorText = findViewById(R.id.u_minor_text);
TextViewCompat.setAutoSizeTextTypeWithDefaults(text, TextViewCompat.AUTO_SIZE_TEXT_TYPE_UNIFORM);
Check this link:
https://developer.android.com/guide/topics/ui/look-and-feel/autosizing-textview

center image inside button

i have this code for displaying an image on a button.
How to position the image so that it doesn't touch the frame/border?
this the code:
<Button
android:layout_width="0dp"
android:layout_weight="0.45"
android:onClick="EXIT"
android:layout_height="95dp"
android:text="Exit"
android:textSize="22sp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:background="#drawable/buttonnew"
android:textStyle="bold"
android:drawableTop="#drawable/zexit"
android:textColor="#000000"
android:layout_gravity="bottom"
/>
Since you are referring to the Button rather than the drawable, it would be best to use padding instead of margin, e.g. android:paddingTop

Android RelativeLayout Design issues

I designed one layout which have total 4 RelativeLayout one is outer cover and 3 are child of it. When I put White color in the outer layout than no spaces are left but when I put 9patch image as drawable image than little default padding/margin are left. Is there any properly which solve the padding/margin issue? I have tried margin negative but it will hide bit layout I think it is not proper solution, here is my layout
when I put white color as background than my layout look like
Here is the following code of my layout
<RelativeLayout
android:id="#+id/DetailSection1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/HeaderLayout"
android:layout_toLeftOf="#+id/DetailSection2"
>
<TextView
android:id="#+id/lblRestaurantName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/DetailSection1"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:textColor="#color/heding_font"
android:textSize="#dimen/headingFont"
android:text="Restaurant Name" />
<ImageView
android:id="#+id/imgpin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/lblRestaurantName"
android:layout_margin="5dp"
android:src="#drawable/pin" />
<TextView
android:id="#+id/lblAddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/lblRestaurantName"
android:layout_marginTop="5dp"
android:layout_toRightOf="#+id/imgpin"
android:text="Address"
android:textColor="#color/restaurant_list_font"
android:textSize="#dimen/lableNormalFont"
/>
<ImageView
android:id="#+id/imgphone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/lblAddress"
android:layout_margin="5dp"
android:src="#drawable/phn" />
<TextView
android:id="#+id/lblMobile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/lblAddress"
android:layout_marginTop="5dp"
android:layout_toRightOf="#+id/imgphone"
android:text="Mobile"
android:textColor="#color/restaurant_list_font"
android:textSize="#dimen/lableNormalFont"
/>
<ImageView
android:id="#+id/imgstar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/lblMobile"
android:layout_margin="5dp"
android:src="#drawable/star" />
<TextView
android:id="#+id/lblStar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/lblMobile"
android:layout_marginTop="5dp"
android:layout_toRightOf="#+id/imgstar"
android:text="Star"
android:textColor="#color/restaurant_list_font"
android:textSize="#dimen/lableNormalFont"
/>
</RelativeLayout>
<RelativeLayout
android:id="#+id/DetailSection2"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignBottom="#+id/DetailSection1"
android:layout_toLeftOf="#+id/DetailSection3"
android:layout_toRightOf="#+id/lblStar" >
<ImageView
android:id="#+id/imgmore"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:src="#drawable/read_more" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/DetailSection3"
android:layout_width="95dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/HeaderLayout"
android:layout_gravity="center"
android:layout_centerInParent="true"
android:background="#drawable/photo_cover" >
<ImageView
android:id="#+id/imgRestaurant"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/lblMobile"
android:layout_margin="5dp"
android:src="#drawable/rihanna" />
</RelativeLayout>
</RelativeLayout>
From the 9-patch drawable image you posted:
The bottom line which indicates the horizontal data population on the view wasn't drawn from the starting point of left.
I am not sure about it. And I know I wasn't clear in explaining the above line.
Just check this:
Consider the below 9-patch is used as a background for a TextView. If you put some text in it, it will start from the area where the bottom line is drawn. Which mean it will start from the left and go all the way to right.
If you use the following 9-patch as a background and try the same thing which you did above. Will result in Text not written from the left. It leaves a bit padding.
That is the reason why you get such result. Of course I am 100% sure about it.
So, just to find out if this works. Try changing the bottom line to fill complete image.
I think you better apply the background color for which layout you want exactly.And one more keep the code so that we can understand easily what is your issue.

how do I align text and image in same button

How do I align text and image with same button? I want to do like this image:
but my button looks like this, with text overlapping the image:
This is my code below. How do I make space in between text and image in the same button?
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_weight="0"
android:weightSum="1"
android:orientation="horizontal" >
<Button android:id="#+id/btnUtilitybillpayments"
style="?android:attr/buttonStyleSmall"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:drawableLeft="#drawable/handshake"
android:layout_marginRight="55dip"
android:layout_marginLeft="55dip"
android:drawablePadding="-25dp"
android:paddingLeft="10dip"
android:paddingRight="50dip"
android:layout_marginTop="10dip"
android:background="#drawable/curvedplanebutton"
android:textColor="#drawable/button_text_color"
android:text="Utility Bills Payment"/>
</LinearLayout>
try this
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="#android:drawable/btn_star_big_on"
android:text="Drawable left">
Button>
For more info go to this link
http://izvornikod.com/Blog/tabid/82/EntryId/8/Creating-Android-button-with-image-and-text-using-relative-layout.aspx
I think you made your button to Complex,
Just use below code and let me know what happen..
<Button android:id="#+id/btnUtilitybillpayments"
style="?android:attr/buttonStyleSmall"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_marginRight="55dip"
android:layout_marginLeft="55dip"
android:drawableLeft="#drawable/handshake"
android:layout_marginTop="10dip"
android:gravity="left"
android:paddingLeft="20dip"
android:background="#drawable/curvedplanebutton"
android:textColor="#drawable/button_text_color"
android:text="Utility Bills Payment"/>
As I have also doubt on layout_margin attributes of your Button. If it doesn't work then try to remove
android:layout_marginRight="55dip"
android:layout_marginLeft="55dip"
Some thing like this.
<Button
android:id="#+id/btnUtilitybillpayments"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/curvedplanebutton"
android:drawableLeft="#drawable/handshake"
android:gravity="left|center"
android:text="Utility Bills Payment"
android:textColor="#drawable/button_text_color" />
A more suitable approach is by making the button as a 9patch image. That way, you can define where the text should be by patching the right and bottom side. And there wont be any need for such complex button.
You can go here for more information-
http://developer.android.com/tools/help/draw9patch.html

How to invisible line in list view for android Honey comb

I m creating an app in that app i want to invisible this Mr. bla bla two line when i clicked on chat image.
any suggestion will be appriciate.
thanks in advance.
this is my xml file.
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/task_list_frag_list_message_layout"
android:background="#EBEBEB"
android:layout_marginBottom="10dp"
android:descendantFocusability ="blocksDescendants"
android:layout_marginTop="10dp"
android:layout_below="#+id/task_list_text"
android:layout_marginLeft="80dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/task_list_chat_persion1"
android:text="Mr. Test : "
android:textSize="18dp"
android:layout_marginTop="13dp"
android:textColor="#color/sky_blue_color"
/>
<TextView android:textColor="#color/black_color"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/task_list_chat_text1"
android:text="A send you a data file kindly get it."
android:textSize="18dp"
android:layout_marginTop="13dp"
android:layout_toRightOf="#+id/task_list_chat_persion1"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/task_list_chat_persion2"
android:text="Mr. me : "
android:textSize="18dp"
android:layout_marginTop="13dp"
android:layout_below="#+id/task_list_chat_persion1"
android:textColor="#color/sky_blue_color"
/>
<TextView android:textColor="#color/black_color"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/task_list_chat_text2"
android:text="I got the data file and i have some doubt in them"
android:textSize="18dp"
android:layout_marginTop="13dp"
android:layout_below="#+id/task_list_chat_persion1"
android:layout_toRightOf="#+id/task_list_chat_persion2"
/>
</RelativeLayout>
this two lines are ij relative latout.
I think you want this ...
just need to add onClick() event on chat image and then on clicking set visibility of TextView to invisible by code.
TextView _text= (TextView)findViewById(R.id.task_list_chat_text);
_text.setVisibility(TextView.INVISIBLE);
When you click on chat button in the list view you should setTest="" blank for both remove it.
It may be solution of this problem.

Categories

Resources