Make sure right view is selected as anchor on "more"-expansion
This commit is contained in:
parent
734741c8f4
commit
65b16beb61
@ -317,14 +317,11 @@ public class AppDetailsRecyclerViewAdapter
|
|||||||
descriptionMoreView.setOnClickListener(new View.OnClickListener() {
|
descriptionMoreView.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
// Remember current scroll position so that we can restore it
|
// Make this "header section" the focused child, so that RecyclerView will use
|
||||||
LinearLayoutManager lm = (LinearLayoutManager) recyclerView.getLayoutManager();
|
// it as the anchor in the layout process. Otherwise the RV might select another
|
||||||
int pos = lm.findFirstVisibleItemPosition();
|
// view as the anchor, resulting in that the top of this view is instead scrolled
|
||||||
int posOffset = 0;
|
// off the screen. Refer to LinearLayoutManager.updateAnchorFromChildren(...).
|
||||||
if (pos != RecyclerView.NO_POSITION) {
|
recyclerView.requestChildFocus(itemView, itemView);
|
||||||
View firstChild = recyclerView.getChildAt(0);
|
|
||||||
posOffset = (firstChild == null) ? 0 : (firstChild.getTop()); // - recyclerView.getPaddingTop());
|
|
||||||
}
|
|
||||||
if (TextViewCompat.getMaxLines(descriptionView) != MAX_LINES) {
|
if (TextViewCompat.getMaxLines(descriptionView) != MAX_LINES) {
|
||||||
descriptionView.setMaxLines(MAX_LINES);
|
descriptionView.setMaxLines(MAX_LINES);
|
||||||
descriptionMoreView.setText(R.string.more);
|
descriptionMoreView.setText(R.string.more);
|
||||||
@ -332,10 +329,6 @@ public class AppDetailsRecyclerViewAdapter
|
|||||||
descriptionView.setMaxLines(Integer.MAX_VALUE);
|
descriptionView.setMaxLines(Integer.MAX_VALUE);
|
||||||
descriptionMoreView.setText(R.string.less);
|
descriptionMoreView.setText(R.string.less);
|
||||||
}
|
}
|
||||||
if (pos != RecyclerView.NO_POSITION) {
|
|
||||||
// Restore scroll position
|
|
||||||
lm.scrollToPositionWithOffset(pos, posOffset);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// Set ALL caps (in a way compatible with SDK 10)
|
// Set ALL caps (in a way compatible with SDK 10)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user