I got inspired with new look of Google Play Market and decided to change the way “Is it kosher?” app shows detailed information with picture.
So, I got an idea to show image with overlay, which will be scrolled down and the picture will be shown in full.
Here is the result of my work:
Solution appeared to be not the simplest one – spend several days on research.
Layout looks as following:
.....
Java code contains the following lines:
int viewHeight = 0; int innerViewHeight = 0; final View view = inflater.inflate(R.layout.itemview, container, false); final LinearLayout innerView = (LinearLayout)view.findViewById(R.id.innerView); ViewTreeObserver vto = view.getViewTreeObserver(); vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { viewHeight = view.getHeight(); innerViewHeight = innerView.getHeight(); innerView.setPadding(0, viewHeight, 0, 0); ViewTreeObserver obs = view.getViewTreeObserver(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { obs.removeOnGlobalLayoutListener(this); } else { obs.removeGlobalOnLayoutListener(this); } } }); final ScrollView scrollview = ((ScrollView) view.findViewById(R.id.ScrollView)); scrollview.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { scrollview.post(new Runnable() { public void run() { if (innerViewHeight >= viewHeight) { scrollview.scrollTo(0, viewHeight-100); }else { scrollview.fullScroll(View.FOCUS_DOWN); } } }); } });
Some explanations:
– innerView gets padding dynamically. This is done to make sure that there is enough space for showing the picture in fill.
– viewHeight calculations are done in OnGlobalLayoutListener due to the reason, that whole View should be loaded first to obtain the real dimensions.
– I wanted to make overlay to be seen on the moment of page open, but not scrolled fully till the bottom. For that purpose we start new Thread with scrolling in OnGlobalLayoutListener. I haven’t found other way to solve this task and seems to be it is the best one. I want to have a small step-down, that is why there is such solution.
sir pls provide whole source code if possible ….plsssssss