I'd like to have LinearLayout with background set to some drawable.
Can I round it's corners somehow as it could be done with shape and gradient?
Main problem is I need to be repeating the bitmap so it matches view's size
Try this and add it as a bacground to your Xml item :
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#dadada"/>
<corners
android:topLeftRadius="13dip"
android:topRightRadius="13dip"
android:bottomLeftRadius="13dip"
android:bottomRightRadius="13dip"/>
<stroke android:width="1dip" android:color="#ff000000"/>
</shape>
Edit : you can define an ImageView in your LinearLayout then you can set it's background to your rounded shape
ImageView IV=(ImageView)findViewById(R.id.imageView);
IV.setBackgroundResource(R.drawable.round_border);
This is workaround which works perfectly as long you have single color background #000000 should be the background color:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<bitmap android:src="#drawable/action_bar_background" android:tileMode="repeat"/>
</item>
<item>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<stroke
android:width="5dp"
android:color="#000000" />
<solid android:color="#00000000"/>
<corners android:radius="7dp" >
</corners>
</shape>
</item>
<item>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<stroke
android:width="5dp"
android:color="#000000" />
<solid android:color="#00000000"/>
</shape>
</item>
</layer-list>
Related
I have a shape rectangle in my drawable like this
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:radius="2dp"
android:topRightRadius="0dp"
android:bottomRightRadius="0dp"
android:bottomLeftRadius="0dp"/>
<stroke
android:width="1dp"
android:color="#android:color/white"
/>
</shape>
How, can I hide bottom line ?
<?xml version="1.0" encoding="UTF-8"?>
<!-- inset is used to remove border from top, it can remove border from any other side-->
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:insetTop="-2dp">
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:id="#+id/rectangle">
<stroke android:width="1dp" android:color="#b7b7b7" />
<corners android:bottomRightRadius="5dp" android:bottomLeftRadius="5dp"/>
<solid android:color="#454444"/>
</shape>
</inset>
use this code
<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android">
<!-- the line -->
<item>
<shape>
<solid android:color="#yourColor"
/>
</shape>
</item>
<!-- This is full view -->
<item android:bottom="10dp">
<shape>
<solid android:color="#backGroundColor" />
</shape>
</item>
this will add a 10dp height line at bottom of your view , u can change size of the line with
<item android:bottom="10dp">
and change color too
good luck
I'm developing an android app and have some trouble with a drawable.
I tried to achieve a corner like this
https://imgur.com/DYWfsZI
I only want the red area and the white must be transparent.
(best of course as xml)
Try this:
1: Define top_left_outer_bg.xml in drawables:
<?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="#android:color/holo_red_dark" />
</shape>
</item>
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#android:color/white"/>
<corners android:radius="50dp"
android:topRightRadius="0dp"
android:bottomRightRadius="0dp"
android:bottomLeftRadius="0dp"/>
</shape>
</item>
</layer-list>
2: Add top_left_outer_bg.xml as background to your layout
android:background="#drawable/top_left_outer_bg"
<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="oval"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<solid android:color="#ffffff"/>
<stroke android:width="30dp"
android:color="#51000000"
/>
</shape>
It gives a "half-inner-half-outer" stroke.
What I need is outer semitransparent stroke only. Can it be done?
What I have is
What I need is
Thanks
you can check this shape created using layer list with it's items.
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item >
<shape android:shape="oval" >
<solid android:color="#fff" />
</shape>
</item>
<item >
<shape android:shape="oval">
<solid android:color="#android:color/transparent" />
<stroke
android:width="50dp"
android:color="#30000000" />
</shape>
</item>
</layer-list>
if you add alpha for stroke color the inner half is without transparent and outer is transparent.this is how stroke color works.if you don't want inner circle use color without Alpha and adjust Hexcode.
Try adding android:innerRadius="0dp" for shape attribute -
<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="oval"
xmlns:android="http://schemas.android.com/apk/res/android"
android:innerRadius="0dp"
>
<solid android:color="#ffffff"/>
<stroke android:width="4dp"
android:color="#51000000"
/>
</shape>
This is Android studio XML preview bug.look like The image you shown above from Android studio xml preview.actually there is no inner and outer layer.
I've found no way to do that other than the following:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item >
<shape android:shape="oval">
<solid android:color="#android:color/transparent" />
<stroke
android:width="#dimen/stroke_width"
android:color="#33000000" />
</shape>
</item>
<item >
<shape android:shape="oval" >
<solid android:color="#fff" />
<stroke
android:width="#dimen/stroke_width"
android:color="#android:color/transparent">
</stroke>
</shape>
</item>
</layer-list>
Try This: (Change dimens and colors to fit your needs)
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<stroke android:width="#dimen/default_stroke_size_small" android:color="#color/colorDimBlack"/>
</shape>
</item>
<item>
<shape android:shape="oval">
<stroke android:width="#dimen/default_stroke_size_small" android:color="#android:color/transparent"/>
<solid android:color="#color/colorWhite"/>
</shape>
</item>
</layer-list>
update your code to this:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#ffffff" />
<stroke
android:width="30dp"
android:color="#000000" /> <--- this line you have to change
</shape>
You are missing one f in your first color. Thus it's creating a half visible pattern
<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="oval"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<solid android:color="#fffffff"/>
<stroke android:width="30dp"
android:color="#51000000"
/>
</shape>
Is there a way to make a drawable that draws a vertical line? So far I have a horizontal line that draws this:
current code is as follows:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/object_switcher_background" />
<item android:left="0dp"
android:right="250dp">
<shape android:shape="line">
<stroke android:color="#color/c19"
android:width="2dp"/>
<size android:width="40dp"/>
</shape>
</item>
<item android:left="50dp"
android:bottom="50dp"
android:top="75dp"
android:right="150dp">
<shape android:shape="line">
<stroke android:color="#color/c19"
android:width="2dp"
android:rotation="90"/>
<size android:width="40dp"/>
</shape>
</item>
</layer-list>
How can I manipulate this to make it look like this?
You could do this by nesting your second item inside a rotate item.
you can do that using rotate item: the below code defines a white background with a vertical divider using only xml drawable
<?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="#android:color/white" />
</shape>
</item>
<item>
<rotate android:fromDegrees="90">
<shape android:shape="line">
<stroke
android:width="1dp"
android:color="#android:color/darker_gray" />
</shape>
</rotate>
</item>
I'm not sure why you need a drawable for this.
This can also be done by using a simple view and adjusting its height, width and position according to your needs. For example:
<View
android:layout_width="1dp"
android:background="#color/grey_text_color"
android:layout_height="match_parent"/>
this is my xml file which add border around linear layout how do i add gradient color effect code inthis code? i want replace this color #C0C0C0 with gradiend color
below is my code
<?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="#000000" />
</shape>
</item>
<item
android:left="1dp"
android:right="1dp"
android:top="2dp"
android:bottom="2dp" >
<shape android:shape="rectangle">
<solid android:color="#C0C0C0" />
</shape>
</item>
</layer-list>
i want to add this code in my border .xml file how i merge??
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#fefdfe"
android:endColor="#e8e3ec"
android:angle="90" />
</shape>
fill layout with gradient:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<gradient
android:startColor="#4fc939"
android:centerColor="#0c87c5"
android:endColor="#b4ec51"
android:angle="180" />
</shape>
</item>
Just replace
<shape android:shape="rectangle">
<solid android:color="#C0C0C0" />
</shape>
with your gradient shape.
Try this:-
<shape android:shape="rectangle">
<gradient
android:startColor="#5a5a5a88"
android:endColor="#14141488"
android:angle="270" android:centerX="0.25"/>
</shape>