The question is quite simple. How do I get this imageview below to be visible in front of the button below?
I am looking for an XML answer, not a Java answer. Seeing java (I think) will not change anything in the preview screen while working on the xml file.
<ImageView
android:layout_width="35dp"
android:layout_height="35dp"
android:background="#drawable/iconfb"
android:layout_marginTop="90dp"
android:layout_marginLeft="12.5pt"
android:id="#+id/iconfb"
/>
<Button
android:layout_width="300dp"
android:layout_height="40dp"
android:text="Sign in with facebook"
android:onClick="invokefb"
android:textColor="#color/white"
android:textStyle="bold"
android:background="#color/tmfacebook"
android:layout_marginTop="-20dp"
android:layout_marginLeft="12.5pt"
android:id="#+id/fblogin"
"/>
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawablePadding="10dp"
android:drawableLeft="#drawable/fb"
android:text="Facebook"/>
Related
I am a new beginner in android development and try to give margin SVG google icon from the top inside the button on the search bar.I know its quick fix but I already try margin properties not affected!
XML
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:drawableTop="#drawable/ic_search"
android:textColor="#FFF"
android:background="#3bbdfa"/>
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/button1"
android:layout_alignParentLeft="true"
android:ems="13"
android:textColor="#CCC"
android:hint="Search..."
android:background="#null"
android:layout_marginLeft="15dp"
android:layout_marginTop="15dp"
android:layout_marginBottom="15dp" />
output
see search-bar here
can anyone have the solution? any help is appreciated.
You can use a ImageView instead a Button as explained in this answer,
Center a drawable in a Button with background and no text
I am unable to get the '×' (multiplication symbol) in the shown button exactly in the centre. It seems a bit off. How can I bring it back in centre?
Here is the xml code for it.
<Button
android:id="#+id/button_multiply"
android:layout_marginLeft="24dp"
android:layout_marginRight="16dp"
android:alpha="0.5"
android:background="#drawable/rounded_corner"
android:elevation="24dp"
android:onClick="onClick"
android:text="#string/button_multiply"
android:textColor="#android:color/white"
android:textSize="30sp"
android:gravity="center"
android:layout_width="60dp"
android:layout_height="60dp" />
Thanks for help
It's an odd problem that catches everyone at first - you need text alignment AND gravity which must match
<Button
android:textAlignment="center"
android:gravity="center"
... />
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"/>
I have an image button inside a frame layout inside of a relative layout. I add the following to the image button android:rotation="-90" but the image button doesnt appear to change.
View Hierarchy
XML
<ImageButton
android:id="#+id/profile_pic_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#drawable/round_profile_pic_btn"
android:contentDescription="profile picture button"
android:padding="20dp"
android:rotation="-90"
android:layout_gravity="center"
android:src="#drawable/ic_face_black_48dp"/>
<com.github.lzyzsd.circleprogress.DonutProgress
android:id="#+id/donut_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
custom:donut_progress="70"
custom:donut_text_size="0dp"
android:layout_alignTop="#+id/profile_pic_btn"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_above="#+id/textView5"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_gravity="center" />
Could not post as comment as my rep is not there yet. Did you try it in any emulator or actual device? I copied your xml (except the circleprogress.DonutProgress stuff) and it worked in the emulator and device.
The effect is not visible in Design mode though.
I have a Button set up like this:
<Button
android:id="#+id/sendBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="Send"
android:padding="-5dp"
android:paddingBottom="-10dp"
android:background="#color/red"/>
Here is how it looks like in Android 4.0 and above: http://i.imgur.com/2P9WEWp.png?1
Here is how it looks like in Android 2.3: http://i.imgur.com/4oXSN2P.png?1
As you can see, the 2.3 button seems squished together and very small. How can I fix this so new versions and 2.3 atleast have same resemblance?
It's about the device size, create multiple values folder(values, values-sw600dp, values-v11 etc) make each of them has dimens.xml. In dimens.xml define different padding values. Then in your layout file use this values instead of hardcoded ones.
e.g
<Button
android:id="#+id/sendBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="Send"
android:padding="#dimens/padding"
android:paddingBottom="#dimens/paddingBottom"
android:background="#color/red"/>
Use positive values for padding, set textColor attribute for white color:
<Button
android:id="#+id/sendBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="Send"
android:padding="5dp"
android:paddingBottom="10dp"
android:background="#color/red"
android:textColor="#FFFFFF"/>
Moreover, use android-holo-colors to generate a proper styles, selectors, drawables for Button for all APIs.
There is a two ways to solve this problem..
1: need to put padding all side.
<Button
android:id="#+id/sendBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="Send"
android:padding="5dp"
android:background="#color/red"
android:textColor="#android:color/white"/>
2: need to give fixed size for this button.
<Button
android:id="#+id/sendBtn"
android:layout_width="60dp"
android:layout_height="40dp"
android:gravity="center"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="Send"
android:background="#color/red"
android:textColor="#android:color/white"/>
Both are easy and perfect lookup.