Reputation: 111
So, I'm having a very weird problem with GridView on my app.
What I want to do is pretty simple: I just want to get a list of installed apps (a-la app drawer) and display them in alphabetical order in a gridview.
It works pretty well, they all show up nicely, but as soon as I scroll down to see more apps and scroll back up, the apps at the top are slightly offselt. Vertically, to be more exact, and this happens every time I scroll down more than 1-2 rows and scroll all the way back up.
Also, sometimes I'll scroll back to the top and it'll keep scrolling past the top apps into oblivion, and not let me scroll back down. I'm not sure if the problems are related, but I'd sure like to fix both of them. The gridView resets completely to normal after clicking on one of the items or switching windows in the app.
This is only my 2nd day working with android Layouts and such, although I've done Java programming for a long time before, so I might be missing something but I'm not completely new to this.
I've looked online and I can't quite find an answer that works, I've tried all the ones I've found and now I'm just coming accross solutions I already have implemented in my code, so I'm not sure where to go besides here.
I'm also not sure which part of my code to post to figure out this problem, and I don't want to turn this into a huge wall of text with every one of my related files, so I would appreciate it a lot if someone could guide me into what to show.
I'll start with my GridView layout, my individual cell layout, and my adapter's getView method, as those seem to be the places where most of the solutions I found were guided to. Please let me know if you need any more of my code.
layout_grid
<GridView
android:id="@+id/gridView1"
android:layout_width="match_parent"
android:layout_height="488dp"
android:numColumns="5"
android:textAlignment="center"
android:verticalSpacing="5dp" >
</GridView>
</LinearLayout>
layout_app
<ImageView
android:id="@+id/ivIcon"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="5dip"
android:scaleType="center"
android:adjustViewBounds="true"
/>
<TextView
android:id="@+id/tvName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
/>
</LinearLayout>
getView
public View getView(int position, View convertView, ViewGroup parent) {
View v;
if(convertView == null){
v = LayoutInflater.from(mContext).inflate(R.layout.layout_app, null);
//mContext is defined in the constructor for my Adapter
}else{
v = convertView;
}
ImageView icon = (ImageView)v.findViewById(R.id.ivIcon);
TextView name = (TextView)v.findViewById(R.id.tvName);
icon.setImageDrawable(getItem(position).getIcon());
name.setText(getItem(position).getName());
//getIcon and getName are from a custom App class made to store app info.
return v;
}
I have pictures of what it looks like, but it's not letting me post them or give links to all of them because of my reputation, so if you want to see something specifically just ask me.
P.S.: Another minor problem I'm having is that some icons don't seem to be scaling down completely to the size of the ImageView, but that's totally unrelated as far as I know and not the major point of this post. You can help me with that too if you want, though :P
Upvotes: 2
Views: 476
Reputation: 111
I figured it out, although I'm not too sure why it was happening. Apparently, since I didn't have a hardcoded height for my individual cells, they would adjust to the text around them and change size, therefore changing the position of the other ones. I still don't really know why the whole overscrolling thing happens, I think it's just a bug with the gridview but I find it weird that no-one else has mentioned it. Oh well...
Upvotes: 3