I created custom triangle button, from code which was given by wonderful user so, here :
How to create layout with buttons like on this picture? ( BUTTON THAT HAVE ACTUALLY SHAPE OF TRIANGLE, NOT MASK )
And i came in level, for adjusting design. I tried to make 9-patch img, also with normal, but it looks for inner button like this:
And then bump into finding way for adjusting that image into triangle custom button, and found this solution:
Android - Image Button Scale
But what i got is not good for me. Here what i tried :
<FrameLayout
android:layout_width="270dp"
android:layout_height="270dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="#drawable/custom_border" >
<custom_button.TriangleButton
android:id="#+id/btn_bottom"
android:layout_width="250dp"
android:layout_height="200dp"
android:text="Second Button"
android:textColor="#000"
android:layout_gravity="center_horizontal"
android:gravity="bottom|center_horizontal"
android:padding="13dp"/>
<custom_button.TriangleButton
android:id="#+id/btn_top"
android:layout_width="130dp"
android:layout_height="110dp"
android:text="First Button"
android:textColor="#000"
android:layout_gravity="center_horizontal"
android:gravity="bottom|center_horizontal"
android:layout_margin="55dp"
android:padding="30dp"
android:onClick="callAdditionActivityButton"
android:src="#drawable/triangle"
android:adjustViewBounds="true"
android:scaleType="fitXY"/>
</FrameLayout>
I have on mind to create triangle (with my art) in rectangle (normal image) to fit center of rectangle, in way, down_left_corner, center_top, down_right_corner, respectivly created in code. And around triangle make transparent. How to achieve this? Main issue how to adjust picture, second is transparent background...
EDIT: My image's size is: 502 x 302, bit depth 32
MY desired picture for adjusting, i want this circle to be in center in custom button :
Related
I created a personal keyboard and set the background image to the one of the buttons, but after that button size (with my background) is different from one another.
<Button
android:id="#+id/buttonShift"
android:paddingTop="0dip"
android:textSize="22sp"
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1"
android:textStyle="bold" />
Set background:
<Button
android:id="#+id/buttonShift"
android:background="#drawable/sym_keyboard_shift_off"
android:paddingTop="0dip"
android:textSize="22sp"
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1"
android:textStyle="bold" />
Please, see the screen of the buttons
Before:
After:
Image size: 106x68
I would advise you to:
Change your drawable a bit - remove the orange rectangle background, keep only the arrow with transparent background (from now on I will use the name shift_off_arrow as a name of described drawable). The transparent background should be only as big as it is needed to keep the whole arrow. Not bigger.
Define a new color - the color of your orange background (from this moment I will assume you have defined it and I will be using name orange_background)
Use ImageButton instead of Button (just like satnam singh and Hamid Shatu said in a comments to your question)
Use code like this (manipulate with all paddings to get the size of the arrow exactly like you want):
<ImageButton
android:id="#+id/buttonShift"
android:background="#color/orange_background"
android:src="#drawable/shift_off_arrow"
android:paddingTop="0dip"
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1" />
i have the a 9 patch image with a magnifying glass icon on the right side for my search box,
the problem is, the image doesn't fit well while i put it as background for my edittext.
(i can't upload the screenshoot yet)
the magnifying glass icon didn't work as expected, the icon got shrunk there. can someone help me fix this?
here my XML code :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ListFoodActivity"
android:padding="10dp"
android:background="#drawable/bcground"
android:src="#drawable/bcground" >
<TextView
android:id="#+id/textView1"
android:layout_width="100dp"
android:layout_height="30dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="10dp"
android:layout_marginLeft="5dp"
android:text="Food"
android:textSize="20sp"
android:textStyle="bold" />
<EditText
android:id="#+id/editText1"
android:layout_width="150dp"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/textView1"
android:background="#drawable/search"
android:hint="Search"
android:textSize="20sp"
android:textStyle="bold" />
here the 9 patch image :
and the image of the emulator :
sorry for the bad english :(
The problem is the 9 patch itself: it's malformed.
The black line on the left side is simply WRONG (it "touches" the lens).
It should be a single pixel near the lower part, so that its prolongation doesn't touch the lens.
This is it
Note that the lens will be up-right aligned.
If you want it centered, you have to add another black pixel near the upper left border (but you have to replace some pixels near the upper lens frame, too).
Also not thet you don't need the horizontal part being that wide, you can make it much narrower, to save on the final patch size.
After using 9patch to create a photo, you can a image file which it's file extension is XX.9.png.
For example, search.9.png in drawable folder and you should use "android:background=#drawable/search" in xml.
Starting in Android development, i wonder how to do this layout in XML (using Android Studio), targeting 4.x Android devices.
How to precisely position 4 buttons on a bitmap background? Should work despite bitmap scaling.
Scenario:
My application main screen should consist of 4 buttons placed on a bitmap. Button positioning should always look exactly like this, and the whole should scale up/down (proportional width/height) to match the screen space. A layout sketch:
Tried solutions:
4 Buttons in a GridLayout with background:
<GridLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_centerHorizontal="true"
android:orientation="horizontal"
android:columnCount="2"
android:rowCount="2">
<Button android:id="#+id/button1"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Button1" />
<Button android:id="#+id/button2"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Button2" />
<Button android:id="#+id/button3"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Button3" />
<Button android:id="#+id/button4"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Button4" />
</GridLayout>
4 Buttons in a GridLayout, above a ImageView in a RelativeLayout.
One ImageView with onTouch() that checks a colorcoded bitmap. (source here)
The only solution that worked ok regarding scaling is the onTouch(), but i'd rather keep using actual buttons so keyboard navigation and press/hover effects work as expected.
How is it possible to position buttons, to have them always match scale with the bitmap?
Thanks for any insights.
Due to the title this question looks like a dupe but i havent found any that demonstrate how this can be accomplished.
I had this problem and I mathed my way around it. It's pretty horrible but let's say that your background image is 500x500px and on an image like that your button is supposed to be at (100, 100) with a size of 50x50px relative to that background image. When you lay it out you have to get the size of the current device, let's say it's 700x800px in size (these devices most likely do not exist). In this case you would have to set the width of your button to (700/500)*50px and the height would be (800/500)*50px . The position of the button would then be at (700/500)*100 and (800/500)*100 .
You are pretty much scaling the button with the background image. Hopefully I'm making myself clear :)
you can try this, hope will help
<ImageButton
android:id="#+id/notificationform_btn_Approve"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:src="#drawable/btn_approve"
android:onClick="btnApprove_Click" />
and take a look here
and why don't you use ImageButton instead:
<ImageButton android:src="#drawable/greybutton"
android:scaleType="fitCenter" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
then you can adjust the scaling with the scaleType attribute. The only downside is you can't set any text.
good luck
This is what I want to do: customize the image size because it's just a little too big.
I am creating an Android application and in a button, I have the image and text. Now I want to customize the size of the image to fit on the screen. However, I have a difficulty manipulating the image. If I adjust the width and height, it is of the button's. I wanted to adjust the image size. Is this possible?
Here's the code snippet of the button:
<Button
android:id="#+id/marketBtn"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:layout_weight="1"
android:background="#drawable/unselected_button"
android:drawableTop="#drawable/market_icon_0"
android:gravity="center"
android:paddingBottom="5dp"
android:paddingLeft="1dp"
android:paddingRight="1dp"
android:paddingTop="5dp"
android:text="#string/task_bar_lbl_market"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#FFFFFF"
android:textSize="10sp" />
Do you have any idea how to do it? Or what are the possible approaches to fulfill this task?
Use nine-patch.
you can set stretchable area and padding area.
http://developer.android.com/tools/help/draw9patch.html
I am trying to achieve something that on the face of it I thought would be easy but have researched loads and still struggling.
I am setting an ImageView that will act as a background where parts of the image are areas that buttons should sit on top. For example the background looks a bit like this:
This is set to fitCenter so that it scales with the correct aspect ratio on all screen types like this:
Now I am trying to place ImageButtons over the white areas like so:
I am trying this by aligning each Imagebutton to the top left of the background imageView and then setting margins to aset it in the right place. This works for some screen types, but when the background gets resized because the device is smaller than the background image for example I am finding that the buttons on top dont resize with it so I get the effect like the following:
Here is the type of layout I am trying (with just one button here):
<RelativeLayout android:layout_height="match_parent" android:layout_width="match_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:id="#+id/outer" xmlns:tools="http://schemas.android.com/tools">
<ImageView android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="#+id/imageView1" android:src="#drawable/no_pills_pane" android:scaleType="fitCenter" android:adjustViewBounds="true" android:layout_centerVertical="true" android:layout_centerHorizontal="true"/>
<ImageButton android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="#+id/imageButton1" android:src="#drawable/pill_pink" android:scaleType="fitXY" android:background="#null" android:layout_marginTop="50dp" android:layout_marginLeft="44dp" android:layout_alignTop="#id/imageView1" android:layout_alignLeft="#id/imageView1"/>
</RelativeLayout>
I'm sure there must be an easier way to go about this, any help would be greatly appreciated.
Thanks
Simon
If all you need is to center ImageButton within ImageView, simply set alignBottom, alignLeft, alignRight, alignTop to ImageView
android:layout_alignBottom="#+id/imageView1"
android:layout_alignLeft="#+id/imageView1"
android:layout_alignRight="#+id/imageView1"
android:layout_alignTop="#+id/imageView1"