I want to achieve something like this :
I want to make the button transparent Which I have successfully done, now tell me how can I show the line on the upper border of the button and between the two button. How can I handle this. my xml of button is simply goes like this
<LinearLayout
android:id="#+id/buttons"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
android:layout_alignParentBottom="true"
android:weightSum="2">
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text=" Send Message"
android:layout_weight="1"
android:background="#android:color/transparent"
android:textColor="#ff4444"/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Cancel"
android:layout_weight="1"
android:background="#android:color/transparent"
android:textColor="#ff4444"/>
</LinearLayout>
So How can I achieve the borders like this as shown in picture below.
pardon me , for the small size picture as I have this only single image to clear my question .
If you would like to add separator line, please add this:
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#android:color/darker_gray"/>
I would use realitveLayout instad of LinearLayout, so you can set the position of the separators more quickly. You are going to have 2 separators, one is the horizontal, with layout_width="match_parent" and one between the elements.
Android draw a Horizontal line between views
Android Drawing Separator/Divider Line in Layout?
You can define your own shape and add to the Button, as background:
use it as R.drawable.myshape:
place it to res/drawable/myshape.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:startColor="#FFFEEE"
android:endColor="#00FFFF"
android:angle="270" />
<corners android:radius="5dp" />
<stroke android:width="7px" android:color="#EE0FF0" />
</shape>
if you would like to be transparent as well, try this:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:innerRadius="0dp"
android:shape="ring"
android:thicknessRatio="1.4"
android:useLevel="false" >
<solid android:color="#android:color/transparent" />
<stroke
android:width="4dp"
android:color="#android:color/darker_gray" />
</shape>
Related
I am using android studio, and I try to do some work on UI using some buttons.
I have created a background for some buttons, but when I apply this background on the buttons, the text inside the butons is not centered.
I think the marginof the button remains the same, whereas the applied background creates a smaller square than the marginn of the button. I don't know how to make the margin of the button fit the margin of the square coded in the background xml file.
Here the picture of the problem :
pic1
Here is the code of the background (bg_rectangle_grey.xml) :
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:width="#dimen/_34sdp" android:height="#dimen/_34sdp">
<shape android:shape="rectangle">
<stroke android:width="1dp" android:color="#ff6c7780" />
<corners android:radius="3dp" />
</shape>
</item>
</layer-list>
And here is the code of the xml file with the button :
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="#dimen/_15sdp"
android:style="?android:attr/buttonBarStyle">
<Button
android:style="?android:attr/buttonBarButtonStyle"
android:background="#drawable/bg_rectangle_grey"
android:id="#+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="M" />
I have looked for answers on google but it was never exactly what I am looking for.
If anyone can help.
Thank you in advance
Just use gravity center in button
<Button
android:style="?android:attr/buttonBarButtonStyle"
android:background="#drawable/bg_rectangle_grey"
android:id="#+id/button4"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="M" />
Please remove android:width="#dimen/_34sdp" android:height="#dimen/_34sdp" from below code and try again.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:width="#dimen/_34sdp" android:height="#dimen/_34sdp">
<shape android:shape="rectangle">
<stroke android:width="1dp" android:color="#ff6c7780" />
<corners android:radius="3dp" />
</shape>
</item>
</layer-list>
I have to create buttons styled like this:
Yes, strange I know. Those 2 corners should not scale if button text is shorter / longer.
Is this possible to create it using an XML ?
I tried a vector but the vector scales with the size of button.
Any other idea I have is to do it programmatically, e.g., something like in this answer
(Explanation of the design: we're experimenting with the design. Imagine button with 4 such corners. Buttons next to each other each having 2 corners close to the other one, etc. Our users love fancy design ... . :-) )
you can create customView
<LinearLayout
android:orientation="vertical"
android:layout_marginTop="100dp"
android:layout_marginLeft="100dp"
android:layout_width="100dp"
android:layout_height="wrap_content">
<View
android:layout_marginLeft="90dp"
android:background="#000000"
android:layout_width="match_parent"
android:layout_height="1dp"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:gravity="center"
android:textSize="13dp"
android:textColor="#000000"
android:text="Button text.."
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="50dp" />
<RelativeLayout
android:layout_width="1dp"
android:layout_height="match_parent">
<View
android:background="#000000"
android:layout_width="1dp"
android:layout_height="10dp"/>
<View
android:layout_alignParentBottom="true"
android:background="#000000"
android:layout_width="1dp"
android:layout_height="10dp"/>
</RelativeLayout>
</LinearLayout>
<View
android:layout_marginLeft="90dp"
android:background="#000000"
android:layout_width="match_parent"
android:layout_height="1dp"/>
</LinearLayout>
image like this
Okay after a little research and best practice you surely need a Layerlist as a background for your Button(though even a TextView will work i.e it is also clickable like any view).
SOLUTION:
You will have to open the drawables folder and add a drawable resource called lets say custom_button_background then use this layerlist inside it:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<solid android:color="#000000" />
</shape>
</item>
<item android:top="20dp" android:bottom="20dp" android:left="20dp" android:right="20dp">
<shape>
<solid android:color="#ffffff" />
</shape>
</item>
<item android:right="80dp">
<shape>
<solid android:color="#ffffff" />
</shape>
</item>
<item android:top="80dp" android:bottom="80dp">
<shape>
<solid android:color="#ffffff" />
</shape>
</item>
</layer-list>
Then we are done! This will be our background, In my Android studio the Preview for this look like this:
You can adjust the values to reduce them to your needs. To set this as your Button or any View you simply add this attribute to it:
android:background="#drawable/custom_button_background"
Just adjust the measures to fit your Button Size!
I've read several thing about it but I can't find what I need.
I want to keep the grey arrow but I want to remove the horizontal bar from the default style and have a white background. Do you have any idea of how I can do this ?
Here is what I have now (default spinner style) :
Here is what I want :
I did a little modification based on #Mansur Khan 's answer.
We don't have to add an ImageView in this case because the spinner already has a triangle arrow. So check the code below:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:background="#FFFFFF">
<Spinner
style="#style/Widget.AppCompat.DropDownItem.Spinner"
android:layout_width="match_parent"
android:layout_height="70dp"
android:id="#+id/sign_up_country"
/>
</RelativeLayout>
Here is the screenshot
Before:
After:
For the record, I found an easy solution : Wrap your spinner in a relative layout and add an image :
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/borderbottom_white"<!-- white background with bottom border -->
android:layout_marginTop="15dp" >
<Spinner
android:id="#+id/postfield_category"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:background="#null"
android:minHeight="0dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:src="#drawable/arrowspinner" />
</RelativeLayout>
A simple solution that doesn't require you to create your own drawable for the arrow is to wrap the spinner with a RelativeLayout, and set the background color in the RelativeLayout, not the spinner:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#f00" >
<Spinner
android:id="#+id/spinner1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
Use this:
yourspinner.setOnItemSelectedListener(this);
#Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
((TextView) yourspinner.getSelectedView()).setBackgroundColor(getResources()
.getColor(R.color.your_color));
}
and your class should implement OnItemSelectedListener.
Hi instead of wrapping Spinner component around Parent Layouts like LinearLayout, RelativeLayout etc which increases layout parsing simply create a drawable called spinner_bg.xml under drawable folder.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<bitmap
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:src="#drawable/icn_dropdown_arw" />
</item>
</layer-list>
Set spinner_bg as the background of your spinner and it works like charm:
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:background="#drawable/spinner_bg" />
I think the best way without doing complex layouts is this:
Use this xml for your spinner background and you are good to go!!!
<item android:state_pressed="true">
<shape>
<solid android:color="#color/materialBlueGray600" />
<corners android:radius="3dp" />
</shape>
</item>
<item android:state_selected="true">
<shape>
<solid android:color="#color/materialGray50" />
<corners android:radius="3dp" />
</shape>
</item>
<item>
<layer-list>
<item>
<shape>
<solid android:color="#color/materialGray50" />
<corners android:radius="3dp" />
</shape>
</item>
<item android:gravity="right">
<bitmap android:antialias="true" android:gravity="right" android:src="#drawable/ic_expand_small" />
</item>
</layer-list>
</item>
Here is the code of custom spinner. Please check it out and tell me. Not yet I tested this. So please inform me after checking this whether it solves your problem.
<Spinner
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/spinner_background"
android:gravity="center"
android:paddingRight="10dp"
android:spinnerMode="dropdown"
android:textColor="your text color"
android:textSize="your text size" />
Here is the drawable(spinner_background.xml) to create the background of spinner.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle" >
<solid android:color="border color" />
<corners android:radius="3dp" />
</shape>
</item>
<item
android:bottom="1dp"
android:left="1dp"
android:right="1dp"
android:top="1dp">
<shape android:shape="rectangle" >
<solid android:color="#android:color/white" />
<corners android:radius="3dp" />
</shape>
</item>
</layer-list>
Edit:
please check this link which gives you an idea to do.
Customize spinner background
OR
you can do something like this.
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="spinner background image">
<Spinner
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#null"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:src="arrow image" />
</RelativeLayout>
below layout will create a background in spinner with desire color drop down arrow
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".6"
android:background="#drawable/edit_text_rounded_shape"
android:gravity="center|center_vertical">
<Spinner
android:id="#+id/spinerComanyName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:padding="4dp"
android:layout_weight=".6"
android:layout_gravity="center"
android:entries="#array/spinner_item"
android:spinnerMode="dropdown"
android:theme="#style/Spinner"
/>
</LinearLayout>
<style name="Spinner">
<!-- Used for the bottom line when not selected / focused -->
<item name="colorControlNormal">#color/black</item>
<item name="colorControlActivated">#color/colorPrimary</item>
<!-- colorControlActivated & colorControlHighlight use the colorAccent color by default -->
</style>
edit_text_rounded_shape which provide background color and rounded corner
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp">
<solid android:color="#color/white"/>
<stroke android:color="#color/grey"/>
<corners
android:bottomRightRadius="15dp"
android:bottomLeftRadius="15dp"
android:topLeftRadius="15dp"
android:topRightRadius="15dp"/>
</shape>
A good way to customise spinners and any other Android controls is to use the Android Asset Studio site and choose the Android Holo Colors Generator. This will create all the assets you might need, including the "underline". It also generates the XML files that implement the changes.
Once you download the ZIP file from that site, you just copy the images and XML files into your project.
You can then edit the required image files to remove the underline. They are 9-Patch files, called:
apptheme_spinner_default_holo_light.9.png
apptheme_spinner_disabled_holo_light.9.png
apptheme_spinner_focused_holo_light.9.png
apptheme_spinner_pressed_holo_light.9.png
For a more complete explanation of the process, and to see some of the sample XML files, please refer to my related answer:
Change colour of small triangle on spinner in android
android:layout_alignParentRight="true"
android:layout_width="#dimen/spinner_width"
android:layout_height="wrap_content"
android:id="#+id/spnLocation"
android:entries="#array/labelFamily"
android:layout_centerVertical="true"
android:backgroundTint="#color/color_gray"
this work for me
Always while working with spinners, buttons and EditTexts and also needing to insert a drawable, I often wrap the element (spinner, EditText etc.) in a FrameLayout. Check an example:
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Spinner
android:id="#+id/spinner_component"
android:layout_width="match_parent"
android:layout_height="45dp"
android:background="#drawable/your_rectangle_style"
android:textColor="#color/your_text_color" />
<ImageView
android:layout_width="11dp"
android:layout_height="9dp"
android:src="#drawable/arrow_spinner"
android:layout_gravity="right|center_vertical"
android:layout_marginRight="7dp" />
</FrameLayout>
Another important tip is that FrameLayout allows you to set OnClick functions on the drawable, for instance.
I am using a list view in which I have an xml referencing drawable/list as follows:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
//For the borders
<item>
<shape android:shape="rectangle">
<solid android:color="#color/white" />
<corners android:radius="0dp" />
</shape>
</item>
//For the background color of cells
<item android:top="1px"
android:left="0dp"
android:right="0dp"
android:bottom="1px">
<shape android:shape="rectangle">
<solid android:color="#262626" />
<corners android:radius="0dp" />
</shape>
</item>
</layer-list>
The above code is basically used to define the borders and the background color of cells. However, I want to be able to use line for the borders instead of rectangle so that the bottom border of one rectangle doesnt leave a 1 dp gap between the top border of another rectangle below it.
Please refer the image below:
As you can see from the image, the rectangular bottom border below BOK.L is a little off showing a gap between the top rectangular border of GOOG.OQ Is there a way to fix this such that both the borders either overlap on top of each other and no such double line gap appears or is there a way I can define a line shape such that it is defined above and below all the cells in the pic without a gap?
Any clue?
Thanks!
Justin
The xml file referencing the same (drawable/list) is as follows :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#drawable/list"
android:padding="4dp"
>
<TextView
android:id="#+id/symbol"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="2dp"
android:paddingLeft="8dp"
android:textColor="#color/search_autosuggest_header_text"
foo:customFont="Roboto-Bold.ttf"
android:singleLine="true"
android:layout_toLeftOf="#+id/last_container"
android:ellipsize="end"
android:gravity="left"
android:textSize="14sp"/>
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="8dp"
foo:customFont="Roboto-Regular.ttf"
android:layout_alignParentLeft="true"
android:layout_below="#id/symbol"
android:layout_toLeftOf="#+id/last_container"
android:paddingBottom="4dp"
android:textColor="#color/search_autosuggest_item_subtitle"
android:singleLine="true"
android:ellipsize="end"
android:textSize="11sp" />
<FrameLayout
android:id="#+id/last_container"
android:layout_width="87dp"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:layout_toLeftOf="#+id/net_change_container" >
<TextView
android:id="#+id/last_back"
style="#style/TextView.ListsTextView"
android:layout_width="87dp"
android:layout_height="wrap_content"
android:padding="3dp" />
<TextView
android:id="#+id/last"
style="#style/TextView.ListsTextView"
android:layout_width="87dp"
android:textSize="12sp"
android:layout_height="wrap_content" />
</FrameLayout>
<FrameLayout
android:id="#+id/net_change_container"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:layout_toLeftOf="#+id/percent_change_container" >
<TextView
android:id="#+id/net_change_back"
style="#style/TextView.ListsTextView"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:padding="3dp" />
<TextView
android:id="#+id/net_change"
style="#style/TextView.ListsTextView"
android:layout_width="80dp"
android:textSize="12sp"
android:layout_height="wrap_content" />
</FrameLayout>
<FrameLayout
android:id="#+id/percent_change_container"
android:layout_width="65dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_margin="1dp" >
<TextView
android:id="#+id/percent_change_back"
style="#style/TextView.ListsTextView"
android:layout_width="65dp"
android:textSize="14sp"
foo:customFont="Roboto-Regular.ttf"
android:layout_height="wrap_content"
android:padding="3dp" />
<TextView
android:id="#+id/percent_change"
style="#style/TextView.ListsTextView"
android:layout_width="65dp"
android:textSize="12sp"
android:layout_height="wrap_content"/>
</FrameLayout>
</RelativeLayout>
Also,#jboi with with your fix the screen that I get is:
In order to not have double selectors(and in proper positions like also at the top, at the bottom) you have two cases that you need to tackle, the top element(which needs the selector at the top and bottom) plus every other row which needs the selector only at the bottom(the top will be covered by the selector of the previous element). This has to be done in code, in your adapter(if you were using a simple table you could have just made one drawable for the top element and one for the other elements):
remove the properties like android:top, android:bottom etc from the layer-list(as you'll be setting those in code)
in the getView() method of the adapter retrieve the background of the row view(which will be a LayerDrawable)
based on the position you have(mainly 0 vs any oher position) use the LayerDrawable.setLayerInset() method and set the inset for the layer with index 1(if that is your complete drawable): top and bottom for the first element, top(with a value of 0) and bottom for every other position
You could play with ListView params android:divider and android:dividerHeight, to set a line separator of the color and height you want.
The reason for having two lines is, that the background (second layer) lets shine thru the white part on both ends, at the bottom and the top. Therefore every list entry gets a white line on top and on bottom. As list items have a small distance between each other you see two lines.
Two things you need to do
For each item, let only one (top or bottom) shine thru. Therefore you get only one line per item. The drawable XML for an item:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle">
<solid android:color="#color/white" />
<corners android:radius="0dp" />
</shape>
</item>
<item android:top="1dp"
android:left="0dp"
android:right="0dp"
android:bottom="0dp">
<shape android:shape="rectangle">
<solid android:color="#262626" />
<corners android:radius="0dp" />
</shape>
</item>
</layer-list>
For the whole list, you need the drawable that shows the one missing line. The drawable XML for this looks nearly the same. Just bottom and top is exchanged:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle">
<solid android:color="#color/white" />
<corners android:radius="0dp" />
</shape>
</item>
<item android:top="0dp"
android:left="0dp"
android:right="0dp"
android:bottom="1dp">
<shape android:shape="rectangle">
<solid android:color="#262626" />
<corners android:radius="0dp" />
</shape>
</item>
</layer-list>
I'm trying to set the margin of the buttons to 0, (so no spacing between the buttons).
Basically, I want my buttons to look something like that(with the following style and colors):
Any idea how can I accomplish this kind of task? I do not want to create a 9 patch image by myself (since I don't have any knowledge doing that).
In this specific case, you can do this task easily with XMLs.
This is how you can achieve it in two steps:
Step 1
Create 3 shapes in drawable folder:
First shape is for the left button: shape_button_left.xml. This shape has radial left corners and gradient background.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<stroke
android:width="1dp"
android:color="#BFBFBF" >
</stroke>
<corners
android:bottomLeftRadius="10dp"
android:topLeftRadius="10dp" >
</corners>
<gradient android:startColor="#D2D2D2" android:endColor="#F2F2F2" android:angle="90"/>
</shape>
Second shape is for the center button: shape_button_center.xml. This shape doesn't define anything for corners and also has gradient background.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<stroke
android:width="1dp"
android:color="#BFBFBF" >
</stroke>
<gradient android:startColor="#D2D2D2" android:endColor="#F2F2F2" android:angle="90"/>
</shape>
Third shape is for the right button: shape_button_right.xml. This shape has radial right corners and gradient background.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<stroke
android:width="1dp"
android:color="#BFBFBF" >
</stroke>
<corners
android:bottomRightRadius="10dp"
android:topRightRadius="10dp" >
</corners>
<gradient android:startColor="#D2D2D2" android:endColor="#F2F2F2" android:angle="90"/>
</shape>
Step 2
Now, we can use these shapes in simple views to get the effect of buttons.
In your layout XML add the next code:
<LinearLayout 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"
android:gravity="center" >
<!-- Button Left -->
<LinearLayout
android:id="#+id/button_left"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:background="#drawable/shape_button_left"
android:gravity="center"
android:padding="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Left"
android:textColor="#333333"
android:textSize="20sp" />
</LinearLayout>
<!-- End Button Left -->
<!-- Button Center -->
<LinearLayout
android:id="#+id/button_center"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:background="#drawable/shape_button_center"
android:gravity="center"
android:padding="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Center"
android:textColor="#333333"
android:textSize="20sp" />
</LinearLayout>
<!-- End Button Center -->
<!-- Button Right -->
<LinearLayout
android:id="#+id/button_right"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:background="#drawable/shape_button_right"
android:gravity="center"
android:padding="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Right"
android:textColor="#333333"
android:textSize="20sp" />
</LinearLayout>
<!-- End Button Right -->
</LinearLayout>
That's it
Now, you can add onClick listener in your code to LinearLayouts and work with it like a button.
Testing this code on my mobile gives next result:
Any idea how can I accomplish this kind of task? I do not want to create a 9 patch image by myself (since I don't have any knowledge doing that).
I'm afraid you may not have much choice. The inherent spacing found in between each button is a result of extra transparent pixels built directly into the existing 9-patch backgrounds that the framework uses. To replace this behavior you must set the background of the buttons to a different Drawable that doesn't include this inherent spacing.
Another option would be for you that could be done in code is to create XML drawable shapes to use for each background. You can create an individual shape that has corner radii, a fill gradient, and a stroke just like your image. You can read more about creating XML Drawables in the docs.