Finally after writing my response I think about better search on google :)

And the solution is logical after I put better words on the problem :

                        listView.post(new Runnable() {

                            @Override
                            public void run() {
                                listView.requestChildRectangleOnScreen(view,
                                        new Rect(0, 0, view.getRight(), 
view.getHeight()), false);
                            }
                        });

This will make the scroll happens after the redraw so works with correct 
measures.

Le mercredi 11 juillet 2012 14:42:45 UTC+2, Tolriq a écrit :
>
> Hello,
>
> I'm currently facing a problem and the solution I use does not satisfy me.
> I'm pretty sure there's a correct way to handle this case so I ask here :)
>
> My problem is simple I have a listview with items that have a gone part 
> that I show on the last clicked item.
> This part works well, I also want the clicked item to be fully visible and 
> here's comes trouble.
>
> With non expanding item it's easy to do with requestChildRectangleOnScreen 
> but in my case I can't find a way for the list to be aware of the new size 
> of the item so it will only scroll the item to show the expanded part.
> The solution I use is if the requestChildRectangleOnScreen was in effect 
> or if item is last or before last item then scroll by the size of the 
> expanded item (that i get via measure).
>
> This works but not perfect since sometimes I scroll the list (when i 
> before last item) when it would not have been needed :(
>
> The code used : 
>
>             public void onItemClick(AdapterView<?> arg0, View arg1, int i, 
>> long l) {
>>                 // TODO Auto-generated method stub
>>                 if (curView != null) {
>>                     try {
>>                         curView.setVisibility(View.GONE);
>>                     } catch (Exception e) {
>>                     }
>>                 }
>>
>>                 ListView listView = (ListView) 
>> findViewById(R.id.mediaslist_list);
>>
>>                 curView = ((RelativeLayout) 
>> arg1.getTag(R.id.movieslist_item_details));
>>                 curView.setVisibility(View.VISIBLE);
>>                 int widthMeasureSpec = MeasureSpec.makeMeasureSpec(0, 
>> MeasureSpec.UNSPECIFIED);
>>                 int heightMeasureSpec = MeasureSpec.makeMeasureSpec(0, 
>> MeasureSpec.UNSPECIFIED);
>>                 curView.measure(widthMeasureSpec, heightMeasureSpec);
>>
>>                 if (listView.requestChildRectangleOnScreen(arg1, new 
>> Rect(0, 0, arg1.getRight(),
>>                         arg1.getHeight()), false)
>>                         || listView.getLastVisiblePosition() <= (i + 1)) {
>>                     listView.smoothScrollBy(curView.getMeasuredHeight(), 
>> 150);
>>                 }
>>             }
>>
>
> If someone have the correct way to handle this case thanks for answering :)
>  
> Regards,
> Tolriq.
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to