Full relevant code:
@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
super.onScrollChanged(l, t, oldl, oldt);
//Log.v("SCROLL", String.valueOf(l));
adjustImageSizes();
}
private void adjustImageSizes(){
int width = getWidth();
int[] views = { R.id.imageView1, R.id.imageView2, R.id.imageView3, R.id.
imageView4, R.id.imageView5 };
for(int r : views){
ImageView iv = (ImageView) findViewById(r);
int[] location = new int[2];
iv.getLocationOnScreen(location);
int imageViewCenter = location[0] + 108 / 2; // This can be calculated
for each imageView that is on screen
if(imageViewCenter < 0){
imageViewCenter = 0;
}
if(imageViewCenter > width){
imageViewCenter = width;
}
int scrollerCenter = (getWidth() - getPaddingLeft() - getPaddingRight())
/ 2 + getPaddingLeft();
float offset = Math.abs(scrollerCenter - imageViewCenter);
float ratio = ( offset / ( width / 2) );
// Scale the size.
float scale = .5f + (1.0f - ratio) / 2;
if (scale <= 0) {
scale = 0.1f;
}
int iWidth = (int) (scale * 108 * getResources().getDisplayMetrics().
density);
int iHeight = (int) (scale * 56 * getResources().getDisplayMetrics().
density);
if(r == R.id.imageView5){
//Log.v("LOCATION", String.valueOf(imageViewCenter) );
//Log.v("OFFSET", String.valueOf(offset));
//Log.v("RATIO", String.valueOf(ratio));
//Log.v("SCALE", String.valueOf(scale));
Log.v("DIMS", String.valueOf(iWidth) + ":" + String.valueOf(iHeight) );
}
LinearLayout.LayoutParams layoutParams =
(android.widget.LinearLayout.LayoutParams) iv.getLayoutParams();
layoutParams.height = iHeight;
layoutParams.width = iWidth;
iv.setLayoutParams(layoutParams);
//iv.getLayoutParams().height = iHeight;
//iv.getLayoutParams().width = iWidth;
}
}
--
--
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
---
You received this message because you are subscribed to the Google Groups
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.