Rounded corners not working (in android emulator) - android

I'm having a problem with the rounded corners background shape in the emulator and I really can't figure it out.
The shape code is as follows:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="50dip" />
<stroke
android:width="1dip"
android:color="#ccffffff" />
<solid
android:color="#cc111111" />
<padding
android:left="3dip" android:top="3dip"
android:right="3dip" android:bottom="3dip" />
</shape>
used in the following relative layout:
<RelativeLayout
android:id="#+id/loginboxlayout"
android:layout_width="190dp"
android:layout_height="240dp"
android:layout_centerInParent="true"
android:background="#drawable/rounded"
android:padding="0dp" >
(...)
</RelativeLayout>
On the graphical layout, in eclipse, it displays correctly, but on the emulator it doesn't: screenshots.
I'm using android 4.0.
Thanks in advance.

put shape file in res>layout folder and then
<RelativeLayout
android:id="#+id/loginboxlayout"
android:layout_width="190dp"
android:layout_height="240dp"
android:layout_centerInParent="true"
android:background="#layout/rounded"
android:padding="0dp" >
(...)
</RelativeLayout>

Rect.xml---(Put this XML in drawable folder)
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp" android:paddingTop="50dp"
android:layout_marginLeft="50dp">
<solid android:color="#eeeee0" android:paddingLeft="25dp" />
<stroke android:width="0.8dp" android:color="#000000" />
<corners android:bottomRightRadius="15dp"
android:bottomLeftRadius="15dp" android:topLeftRadius="15dp"
android:topRightRadius="15dp" />
And add it where...watever control you want to round--
android:background="#drawable/rect"
It will work definitely .

Dont use dip as size formate. Use dp instead.
And Replace
<corners android:radius="50px" />
instead of
<corners android:radius="50dip" />
It will solve your issue.
Emjoy. :)

Related

How to get rid of gray space in button?

Button with gray space
Button with gray space
Hi everyone, I'm having a difficult time figuring out how to get rid of a gray space inside my button. I would greatly appreciate the help.
Here is my code for my drawable and button.
<Button
android:id="#+id/buttonLogIn"
android:layout_width="300dp"
android:layout_height="60dp"
android:layout_above="#+id/buttonReg"
android:layout_centerHorizontal="true"
android:layout_marginBottom="36dp"
android:background="#drawable/buttonpink"
android:fontFamily="sans-serif"
android:text="LOG IN"
android:textColor="#color/black"
android:textSize="30dp" />
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="100dp" />
<stroke android:width="5px" android:color="#color/pink" />
</shape>
You could simply add the color to the shape in your drawable using like this
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#color/your_color" />
<corners android:radius="100dp" />
<stroke android:width="5px" android:color="#color/pink" />
</shape>

Can't draw a line?

I want to draw a line as ImageView's background.But it doesn't work?
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="line">
<solid android:color="#FF0000FF" />
<size android:width="10dp"
android:height="2dp"/>
</shape>
Just a demo.
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/dividing_line"
android:layout_marginLeft="10dp" />
ImageView has no content so size will be 0x0dp. If you want a divider try setting the width to match_parent and the height to whatever you feel comfortable with (2dp for example).
Update: Try this.
In your layout file:
<ImageView
android:layout_width="match_parent"
android:layout_height="4dp"
android:background="#drawable/dividing_line"
android:layout_marginLeft="10dp" />
The drawable:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="line">
<stroke android:width="2dp" android:color="#0000FF"/>
<size android:height="2dp" />
</shape>
It is working for me.
As pointed out by TheTool if you just want a divider the easier solution is to add
<View android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#color/yourColor" />
to your layout file.

Autocomplete textview with oval shape corners

I want to create the shape of autocomplete textview shown in the figure and text should come in center of it.
Currently I am trying to implement it as
<item>
<shape android:shape="rectangle" >
<corners android:radius="15dip" />
<solid android:color="#color/blue_text" />
<padding
android:bottom="5dip"
android:left="15dip"
android:right="15dip"
android:top="5dip" />
</shape>
</item>
<AutoCompleteTextView
android:id="#+id/autoComp"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:background="#drawable/bg_autocompletetext"
android:textColor="#color/white"
</AutoCompleteTextView>
But it would just make the corners of the textview round. It does make it completely round. Please specify any solution for it.
try this code of shape
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<corners
android:radius="100dp"/>
<solid
android:color="#2137FF"/>
<size
android:width="250dp"
android:height="60dp"/>
</shape>
try this tool
Its better to use 9 patch image as a background of your TextView.
With using 9 patch image you can set proper resolution for different resolution device.And it will give you better result .
You write a seperate xml layout(shape.xml) having code:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#DCDCDC" />
<stroke android:width="2.5dp"
android:color="#DCDCDC" />
<corners
android:radius="10dp"/>
</shape>
Then in your main layout add:
<AutoCompleteTextView
android:id="#+id/autoComp"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:background="#drawable/shape"
android:textColor="#color/white"
</AutoCompleteTextView>
Hope this help.
Try this, working for rounded text view
<?xml version="1.0" encoding="utf-8"?>
<!-- res/drawable/rounded_textview.xml -->
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#284A89" />
<corners
android:bottomLeftRadius="30dp"
android:bottomRightRadius="30dp"
android:topLeftRadius="30dp"
android:topRightRadius="30dp" />
</shape>
Add Following file in drawables "searchtextbox_border.xml"
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<corners
android:radius="100dp"/>
<stroke android:color="#color/light_grey"
android:width="1dp">
</stroke>
</shape>
Then Add it as background in your AutocompleteTextview as follows:
<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="32dp"
android:padding="#dimen/padding_10dp"
android:background="#drawable/searchtextbox_border"
android:hint="Search" />

EditText does not get rounded

I am trying to get a rounded EditText.
My EditText in layout is like
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" >
<EditText
android:id="#+id/EditTextSearch"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/edit_round"
android:padding="5dip"
android:singleLine="true" >
<requestFocus />
</EditText>
<ImageView
android:id="#+id/searchBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:src="#android:drawable/ic_menu_search" />
</FrameLayout>
and the drawable I am using as EditText background is like
<?xml version="1.0" encoding="utf-8"?>
<!-- res/drawable/rounded_edittext.xml -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dp"
android:shape="rectangle" >
<solid android:color="#FFFFFF" />
<corners
android:bottomLeftRadius="12dp"
android:bottomRightRadius="12dp"
android:topLeftRadius="12dp"
android:topRightRadius="12dp" />
</shape>
In my XML graphical layout, my edittext looks fine and rounded, but in emulator and also in device it does not look like that?
Does anyone have any idea why could that be?
Thanks
Remove the android:padding="10dp" attribute to make the drawable look like this. I just tested it and removing the padding attribute shows the rounded corners just fine.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="#FFFFFF" />
<padding
android:bottom="10dp"
android:left="10dp"
android:right="10dp"
android:top="10dp" />
<corners
android:bottomLeftRadius="12dp"
android:bottomRightRadius="12dp"
android:topLeftRadius="12dp"
android:topRightRadius="12dp" />
</shape>
To add padding to the Shape Drawable, notice the padding attribute added in the code above.
The proof lies in the pudding: ;-)
Device Screenshot:
Emulator Screenshot:
You didn't provide the stroke element, so you probably just don't see the background (since it's only a white fill!). When you change the background or add a stroke, it should be visible.
Add:
<stroke android:width="2dp" android:color="#000000" />
And poof! The rectangle is visible :) BTW The padding isn't the issue - it's simply ignored.

how to add bottom border in relativelayout

<LinearLayout
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="vertical" android:background="#drawable/settings_border" android:padding="1dp"
android:layout_marginLeft="15dip" android:layout_marginRight="15dip" android:layout_marginTop="5dip">
<RelativeLayout android:id="#+id/map_refresh"
android:layout_height="fill_parent" android:layout_width="wrap_content"
android:background="#drawable/settings_selector_up"
android:padding="15dp">
<TextView android:id="#+id/Text1"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:text="Map refresh period">
</TextView>
<TextView android:id="#+id/TextView09"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:text="1 min"
android:layout_alignParentRight="true"
android:paddingRight="5dp">
</TextView>
</RelativeLayout>
<RelativeLayout android:id="#+id/own_location"
android:layout_height="fill_parent" android:layout_width="wrap_content"
android:padding="15dp"
android:background="#drawable/settings_selector_mid">
<TextView android:id="#+id/Text1"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:text="Own location update period">
</TextView>
<TextView android:id="#+id/TextView09"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:text="1 min"
android:layout_alignParentRight="true"
android:paddingRight="5dp">
</TextView>
</RelativeLayout>
I want set only bottom border in relativelayout. I want to dispaly listview style but not using listview. Lets say each listitem is relativlayout. I want set only bottom border so its look like a listview's divider.
I hope I understood what you said.
in the res folder create a new folder (if you don't already have it) named drawable
there create an xml named "borders.xml"
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient android:angle="90" android:centerColor="#6da23f" android:endColor="#8bc45d" android:startColor="#2f481c" />
<stroke android:width="2dp" android:color="#999999" />
<padding android:bottom="4dp" android:left="3dp" android:right="3dp" android:top="6dp" />
<corners android:radius="10px"/>
</shape>
</item>
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient android:angle="90" android:centerColor="#6da23f" android:endColor="#8bc45d" android:startColor="#4c8a39" />
<stroke android:width="1dp" android:color="#FFFFFF" />
<padding android:bottom="4dp" android:left="3dp" android:right="3dp" android:top="6dp" />
<corners android:radius="10px"/>
</shape>
</item>
</selector>
You can further edit it as you like.
Then select the layout from the Outline and click Background properties, and select the borders xml that you created.
This will create borders for all 4. Alternatively, you can add a simple
<View android:layout_width="1dip"
android:layout_height="fill_parent"
android:background="#FFFFFF" />
line and add it to the bottom of your layout and change the color/size to your liking.
For some reason the other solutions didn't work for me - all borders were shown no matter how I changed it. This worked:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape
android:shape="rectangle">
<stroke android:width="1dp" android:color="#color/gray" />
<solid android:color="#color/gray" />
</shape>
</item>
<item android:bottom="1dp">
<shape
android:shape="rectangle">
<stroke android:width="1dp" android:color="#color/white" />
<solid android:color="#color/white" />
</shape>
</item>
</layer-list>
The color of the border is gray and the background is white for the container (LinearLayout in my example). You can simply change the second item to make the border thicker or have border on the top/left/right.
This is how the layout xml looks like:
<LinearLayout
android:id="#+id/searchWrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:background="#drawable/bottom_gray_border"
android:layout_alignParentTop="true">
<EditText
android:id="#+id/searchEditText"
style="#style/EditTextSearch"
android:hint="#string/find"
android:layout_marginLeft="5dp"/>
</LinearLayout>
I got the idea from here: Is there an easy way to add a border to the top and bottom of an Android View?
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke
android:width="1dip"
android:color="#FF8000" />
<solid
android:color="#00FFFFFF"
android:paddingLeft="10dip"
android:paddingTop="10dip"/>
<corners android:radius="10px"/>
<padding
android:left="10dip"
android:top="10dip"
android:right="10dip"
android:bottom="10dip" />
</shape>
You can save this as borderframe.xml in the res/drawable folder (create it if it doesnt exist yet), and reference it like so: android:background="#drawable/borderframe".
A simple way to display a border is to create a horizontal LinearLayout, and to set its background color and height according to the border you want.

Categories

Resources