Android Gridview No Spacing - android

Good Evening Everyone,
I have a gridview of images, but I want them flush against each other (without the border that appears when tapped).
I've set vertical and horizontal spacing to zero along with the padding. However, when tapped, the gridview "tap border" still shows up. How can I expand my images, or remove that so I no longer see it.
If you're still unclear, I can provide screenshots.
Thanks,
-Mitchell

Try to use nine-patch bitmap as selector.
Also make sure that bottom and right black lines (nine-patch) cover all sides.
In this case your pictures won't have offsets between each other

I think you should use
public void setSelector (int resID)
and set it to drawable that is fully transpert
the drawable you can define at xml file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<stroke android:width="0px" android:color="#android:color/transparent" />
<padding android:left="0dp" android:top="0dp" android:right="0dp"
android:bottom="0dp" />
<corners android:radius="0px"/>
</shape>

Related

Remove the top and bottom padding in a SeekBar

I am trying make a simple music player. When I try to use the android's default seek bar in my music playback controls section, there is a default padding at the top and bottom of the seekbar. The effect I am trying to achieve is similar to the seekbar used in shuttle music player.
But this the effect I'm getting. I would be grateful if any would tell me how to achieve the desired result.I'm using linear layout as the root container.
Because the option of specifying
android:background="#color/your_colour"
will not work because you have two colors there one for the Top and one for the Bottom.
The working solution is by using a layerlist as follows:
Go to your drawable folder create a file call it lets say
back_ground_seek_bar.xml and add the following code inside it:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:bottom="10dp">
<shape android:shape="rectangle" >
<size android:height="10dp" />
<solid android:color="#colour/your_top_color" />
</shape>
</item>
<item android:top="10dp">
<shape android:shape="rectangle" >
<size android:height="10dp" />
<solid android:color="#color/your_bottom_color" />
</shape>
</item>
</layer-list>
Replace the colours with your own colors when you paste this.
Remember we have added top and height of as 10.But because we want our SeekBar to have colour then we have to set the height of seekbar to twice the value so It should be twice and thats 20dp. So we should add our new height of the seekbar to be 20dp as well set the background as the xml we have defined as follows. Go to your SeekBar and paste this:
android:layout_height="20dp"
android:background="#drawable/back_ground_seek_bar"
For customization you can also change the values of height and whatsoever in the drawable/back_ground_seek_bar.xml but it should always be twice. The given height set in SeekBaraim is to divide it equally.

LinearLayout in Android API Level 10 (2.3), background affects whole element

I have the following element
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#drawable/black_border">
And black_border is:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<stroke
android:width="1px"
android:color="#000"/>
</shape>
The desired result is a 1px black border around the elements inside the LinearLayout.
On my device (running 5.0/Level 21) everything looks good, the contents of that element are grouped by a 1px black border.
However, the min sdk my app will support is level 10/2.3 and when I run the app in the emulator the whole background of the LinearLayout is black. It seems like
it is treating the stroke as a fill.
Has anyone come across this?
Edit: I gave the black_border a stroke of white, this somewhat solved my problem. TextViews inside the LinearLayout had no visible border with this change, so a subsequent step was needed to give them a border.
I had the same issue with api level 9.
You have to explicity tell that the solid is transparent.
Try this:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
<stroke android:color="#color/colorPrimaryDark" android:width="2dp" android:height="2dp"/>
<solid android:color="#color/trasparent" android:width="2dp" android:height="2dp"/>
<size
android:width="10dp"
android:height="10dp"/>
</shape>
where colorPrimaryDark is defined as black (#FF000000) and transparent is #00000000
I suggest you to use dp for dimensions instead of px.
I got round this by giving black_border a stroke of white. Subsequently I needed to give any TextViews inside the LinearLayout a border as having a white background made them borderless.

Clipping List Selector

Lets say I have a ListView/GridView with each row consisting of an ImageView. In addition, each row has some padding to it. Ideally in this case, we would want the list selector to be on top so we use drawSelectorOnTop="true". Ok, no problem, except the list selector covers the entire area of the row. Ideally, I would like to have the list selector cover only the area of the ImageView. Below is an example of what I am talking about.
The left is what ideally should happen, and the right is what actually happens.
The only solution I could come up with is to add an extra "empty" View on top of the ImageView that matches in height/width and use that empty View as the selector. I'm wondering if there are any other or better ways to accomplish this?
use layer-list drawable.
drawable/selector_drawable.xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" ><item
android:drawable="#drawable/internet_list_focused_holo_light"
android:top="10dp"
android:bottom="10dp"
android:right="10dp"
android:left="10dp">
</item>
</layer-list>
Use an InsetDrawable as your custom selector with a custom ShapeDrawable
For example:
drawable/my_selector.xml
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="#drawable/my_shape_drawable"
android:insetBottom="10dp"
android:insetLeft="10dp"
android:insetRight="10dp"
android:insetTop="10dp"/>
drawable/my_shape_drawable.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="#color/selector" />
</shape>
This assumes your ImageViews are all of uniform size.

How to create a rectangle shape with 2 sides in android

I want to show edit text box with two sides. so, for that i need to create a rectangle shape with two sides. PLease help some one.
create a drawable under drawable folder and add the belwow contents (border.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<solid android:color="#color/black" />
<stroke android:width="1dip" android:color="#color/white"/>
</shape>
Now set the Background of the EditText to this draw able like :
android:background="#drawable/border"
I think the best way to do this is to create a 9-patch in PhotoShop with required border sides... there are also several other ways... depends on your design.

Add Frame or Border to ImageView and Drop-Shadow

What I'm trying to do will work better with an example image. As you can see below I have a grey background, ontop of that sits a container with some padding containing an image. The container also has a slight dropshadow to it.
What I want to know, is if there's so non-painstaking way of doing this in my layout.xml? In a normal HTML document this would've been easy. But since this is for a mobile app and for a number of screen resolutions and so on, it's proving a bit difficult.
Any advice?
Edit: I eventually settled using a 9patch image. Everyting went really smooth in the creation of it but when I actually use it in my app I see these dark stripes on the right and bottom of the image. The dropshadow seems to work, it's a very light dropshadow.. but those darn stripes??
You can provide a border to a view by writing an xml file (say editBorder.xml) in drawable folder:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<stroke
android:width="5dp"
android:color="#EBDDE2" />
<padding
android:bottom="2dp"
android:left="2dp"
android:right="2dp"
android:top="4dp" />
<gradient
android:centerColor="#color/white"
android:endColor="#color/white"
android:startColor="#color/white" />
<corners android:radius="8dp" />
</shape>
and to provide this border, use statement in ImageView as android:background="#drawable/editBorder"
This should solve your problem. :)
This can be done with proper padding and 9 patch image. See this link, may be it can help you.
ImageView having two property android:background and android:src
http://developer.android.com/reference/android/widget/ImageView.html
Create a blank white frame with drop shadow(Photoshop recommended).
So just do this
<ImageView android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/image"
android:background="#drawable/whiteFrame"
android:padding="10dp" >
</ImageView>
I found this imageView . It's may good for you

Categories

Resources