I am new in android, want to show border in tablelayout.
can any one please help me, it is very critical for me.
Try setting a ShapeDrawable as the background of the elements you want a border on. You can define a ShapeDrawable in an XML file in your res/drawables folder. In particular, the stroke element has the dashWidth and dashGaps parameters that let you make a dashed line:
<stroke
android:width="integer"
android:color="color"
android:dashWidth="integer"
android:dashGap="integer" />
You can also just set a repeating dots image as the background of the entire table, then set a solid background and margin on the cells (see this trick, which is written about solid borders but I'm sure you can fake with a 2x2 repeating bitmap of a checkerboard pattern).
Related
Can you help me with a solution for custom color shadow with gradient effect?
I need this effect for ImageView shadow
For example, I try to use gradient like:
<gradient
android:type="radial"
android:startColor="#000000"
android:endColor="#43bababa"
android:gradientRadius="100dp"
android:angle="270"/>
But this gradient has ring effect, not rounded corners.
There's problem in every possible solution:
About shadows:
You can use CardView. It has rounded corners and shadows out of the box. But as I know compat realization doesn't cut corners of inner layouts. It just fits image in it (as result tiny white strokes around image example)
You can use 9 patch image as background. Not so easy to place layout layers correctly
SOLUTION YOU WILL LIKE:
Use CardView with RoundedImageView
I am trying to create this as a background (blue bg with gray grid lines). Except I don't want to use this image since on larger or smaller screens it will stretch the grid lines and it won't look good. So I think the best way is to specify a background color and then draw another image (1x1 transparent tile) and have it tile/repeat. Does anyone know how to specify multiple backgrounds on 1 view in the styles.xml file?
So far I have this:
<style name="RegularView" parent="#style/BaseView">
<item name="android:background">#00112d</item>
<item name="android:background">#drawable/grid</item>
</style>
Also what is a good width size for a single square, I want it so that the squares fit evenly in the width and height of the screen. There shouldn't be like half a square on the last row or column, if that's possible..
Thanks
You can cut small portion of the image, like one square with border and then declare a xml bitmap resource in your res/drawable folder.
bitmap_resource.xml:
<?xml version="1.0" encoding="utf-8"?>
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/small_part_of_image"
android:tileMode="repeat"/>
after that just set this file as background in your view.
It will repeat itself until it fits the whole view.
Is it possible in Android to programmatically draw a line using a path, such that the middle section is a solid color but both ends fade from that color to transparent? The path will be a series of calculated coordinates.
Yes, use a generic View widget with a drawable that contains a gradient as its background.
Make sure it extends to match_parent in the direction you want it to cut your layout and it's 1px tall or wide in the other dimension.
The gradient should be a simple linear gradient transparent to solid to transparent.
Here is a very nice tutorial.
Update:
The above link is dead, try this one instead.
If you create an outset border in CSS the browser varies the border colour for each edge to make the shape appear to protrude from its parent.
Is there an easy way to do this in an android layout or do I need to set each line colour manually?
Update - added example below:
Example http://www.witzelsucht.co.uk/googleplusheader.png
Set the background of an ImageView to a 9 patched drawable resource with the desired shadow/bevel around the edge. Lets say it takes 5 pixels to create the effect you want. Then set the padding of the ImageView to 5 pixels. Then set the bitmap to any image.
ImageView.setBackgroundDrawable
ImageView.setPadding
ImageView.setImageBitmap
Even easier, use a shape with a stroked border and set it as the background of the view:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#00000000" />
<stroke android:width="1px" android:color="#ffffff" /></shape>
I'm not aware of any native support for Views to have borders. Your question reminded me of this question that I was looking at recently:
Is there an easy way to add a border to the top and bottom of an Android View?
I have some text in a relative layout.I know that we can draw a border with curves using stroke and corner in a separate xml.
Is there a way to apply gradient effect for the border constructed with the stroke? or is there any other way to draw a gradient border?
Thanks in advance.
I don't know of a way to do that trivially, but it seems like you could define two shape drawables and combine with a layer drawable. The bottom one would be a rounded corner rectangle with a gradient, the top one would be a slightly smaller rounded corner rectangle of whatever you wanted the interior color to be. The effect should be something like a stroke gradient, although I haven't tried it.