Gallery items overlapping (bleed in) - android

My probel is that images in my Gallery are bleeding in into each other once I begin scrolling towards the next image.
I am using a android.widget.Gallery connected to a custom adapter I extended from BaseAdapter.
The adapter's GetView() method is like this
public View getView(int position, View convertView, ViewGroup parent) {
ImageView i = new ImageView(mContext);
if (mImageBitmap != null && position < mImageBitmap.length)
i.setImageBitmap(mImageBitmap[position]);
return i;
}

Did you try using android:spacing ( in xml) or setSpacing(int spacing) (in code) on the Gallery?

I actually found the solution to my problem. In getView(), the ImageView I was returning had no background and thus the ImageViews would overlap. I set the background of the ImageView to black before returning it and it looks great

It seems the fading is added automatically and disabling through XML doesn't work.
However disabling programatically seems to work:
Gallery carousel = (Gallery)findViewById(R.id.image_carousel);
carousel.setHorizontalFadingEdgeEnabled(false);

If you have access to the Gallery instance, you can also call the following method to remove the bleed in area:
gallery.setUnselectedAlpha(1.0f);
This also removes the white-ish haziness of the Gallery view.

Related

ListView onItemLongClickListener is not working properly

I am working on a ListView and I have used setBackgroundColor inside onItemLongClickListener on the selected item. My problem is that when I am doing this and scrolling, it is setting color of some invisible child of ListView too. How can it be solved.
Try putting the following attributes in your xml:
`
<ListView
android:dividerHeight="1dp"
android:scrollingCache="false" >
`
this is caused since a listview uses old views in order to avoid re-creation of views when you scroll.
in fact , this is common to all of the adapterView classes .
in order to handle this , store the status of the position of the view (using an arrayList or whatever collection you wish) and on the getView , if the position is set in the list to be of this background , use this background , otherwise use the default background.
for more information about listview , either read the API , or (and i highly recommend it) watch the video "the world of listView" .
In your adapter class:
#Override
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView == null) {
convertView = inflater.inflate(...);
}
convertView.setBackgroundColor(defaultcolor);
...
}
This however will overwrite the background you set in the onlongclicklistener when that view would be redrawn. So you might want to keep a list of the positions of the clicked items so you can set these in the getView method.

How to overlay rows of Android Listview

I am trying to implement the below Android ListView. The each yellow box represents one row of ListView. If you see the rows, each row is over lapped by previous and next row. I have searched Google, but I could not find any proper solutions. If anyone has clues, please let me know.
Thanks in advance.
Think outside the box. Imagine this list not having the rows overlap, but just having diagonal lines on it. In your code, set the Listview's divider height to 0:
ListView listView = (ListView)findViewById(R.id.your_listview);
listView.setDivider(null);
listView.setDividerHeight(0);
Then create two drawables for the rows- one for odd rows, another for even rows:
and
(don't use these two images, as they are not properly/evenly sized, but create the ones for your specific list).
Then create an adapter for your list view - and in its getView method, set the corresponding background to your element:
#override
public void getView(int position, View convertView, ViewGroup parent) {
MyView row;
if(convertView == null) {
row = (MyView)convertView;
}
else {
row = ... //create your view - inflate or create in code
}
row.setBackgroundResource(position%2==1 ? R.drawable.row_odd : R.drawable.row_even);
... //populate the rest of the row with whatever you need
return row;
}
And voila! You get what the effect you need (note, on this schematic the black lines represent the boundaries between rows - these are for schematic purposes only - in your final result you will not have them):
Finally, please note that if you want highlight on your "rows" when an item is selected, you'll have to implement custom state change listeners, which would change the background of the cell that's being selected and also the ones above and below it as to create the proper visual effect.
I got the same issue but I managed to find a solution
In the ListView in the xml you can set a negative dividerHeight, it works for me.
<ListView
...
android:dividerHeight="-5dp" />
I hope it can help someone :)

Android HorizontalScrolling laggy

I have a HorzontalScrollView with a LinearLayout inside. During Runtime I can add more LinearLayouts to the LinearLayout.
Now I have the problem that the Scrollview only scrolls a little bit and not smooth with one finger slide!
Does anyone have a solution for this problem?
HorizontalScrollView doesn't use an adapter that manages the list's memory, therefore it can't handle heavy (images, custom views, etc) lists.
You can use this Horizontal ListView http://www.dev-smart.com/archives/34 but make sure you don't write the on list item click method inside the getView, it will make the list scroll slow. Other than that, that's a great resource for a smooth horizontal list view.
You can also explore the Android view pager, which is also supported on lower Android versions using the compatibility pack: http://developer.android.com/sdk/compatibility-library.html
Edit - something like that in the adapter that inflates the XML you want (the linearLayout) and then populates every view with the relevant data.
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.chat_friends_list_item, null);
}
ImageView status = (ImageView)convertView.findViewById(R.id.status);
ImageView image = (ImageView)convertView.findViewById(R.id.image);
ImageView imageBorder = (ImageView)convertView.findViewById(R.id.image_border);
TextView title = (TextView)convertView.findViewById(R.id.title);
}
The problem was my parent Viewflow because it has stolen the swipe event! The HorizontalListView is too buggy for me! (Problems with size attributes)
However,thank you for your answer! ;)

Updating gridview position with transparent image

I have a gridview set up with a list of images like this:
public int[] tb =
{ R.drawable.tb1, R.drawable.tb2, R.drawable.tb3, R.drawable.tb4,
R.drawable.tb5, R.drawable.tb6, R.drawable.tb7, R.drawable.tb8,
R.drawable.tb9, R.drawable.tb10, R.drawable.tb11, R.drawable.tb12,
R.drawable.tb13, R.drawable.tb14, R.drawable.tb15, R.drawable.tb16,
R.drawable.tb17, R.drawable.tb18 };
I know how to update a particular image by changing the position in the array e.g.
tb[2] = R.drawable.image;
then using
mAdapter.notifyDataSetChanged();
But my problem is, I want to update the image in the grid view and set the alpha so the image is transparent. Now with normal image view it is simple as doing
ImageView iv = (ImageView) findViewById(R.id.aTest);
iv.setAlpha(127);
But how do I apply to this to a specific image in the grid view. The images are stored as a set of ints and the images are applied using the ImageAdapter. So it means I can't just do
tb[0].setAlpha(127);
As it does not recognise it as an image view. I know I can set the imageView in the adapters Alpha, but that means all images will be transparent and I only want a select few to be transparent
So could anyone tell me how I can set it up so I can change one image in the list and make it transparent. I have the onClickItemListener set up so for time being trying to get it set up so when I click an item in the grid view, that image will become transparent.
Been trying lots of different solutions, but just can't seem to find anything that works. Would be very grateful if someone could point me in the right direction!!
There is no easy way to resolve this but here you go -
Modify your getView in your Adapter in this manner. (I am assuming you have a custom adapter, otherwise you will have to write one. See this example on how to do this)
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) {
//create new image view
} else {
// resuse
}
imageView.setImageResource(mThumbIds[position]);
// new code starts
if(clickedLocation == position){
imageView.setAlpha(alphaValue)
}
// new code ends
return imageView;
}
Store the position of the item from the onClickListener as clickedLocation
Now call invalidateViews() method on the GridView object.
Caveats: (Might not be the best way to go about it)
You will be redrawing the entire GridView everytime there is a click, you might see a flickering effect
If your resources are jpg or png then they need they need to be decoded each time

Problem with custom views in Gallery (false focus received by component)

I'm having problem figuring out an issue with the Gallery component. I'm using a simple gallery with a custom Base Adapter. In the getView method, the view representing a gallery item is inflated:
#Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
View promo = inflater.inflate(R.layout.view_promo, null);
ImageView promoBackground = (ImageView)promo.findViewById(R.id.promo_background);
promoBackground.setBackgroundResource(promoResources[position]);
convertView = promo;
}
return convertView;
}
The inflated view also has two simple button with a selector set as background. The problem is that when the gallery item is clicked/touched, the two buttons appear to receive focus, and the selector changes the background of the two buttons (even if the touch not occurs right over them). I've tried disabling both focus and click on all views that could receive the event, but no luck yet.
Any idea is welcomed!
Thanks
I just encountered this same issue, and found a solution here:
Gallery/AdapterView Child Drawable State

Categories

Resources