Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. public void onResponse(.....){
  2. //do stuff with data
  3.  
  4. mAdapter.notifyDataSetChanged();
  5. }
  6.  
  7. ScrollView -> normal LinearLayout(MATCH, WRAP, vertical) -> custom SizeCappedLinearLayout(MATCH, WRAP, horizontal)
  8.  
  9. View heightLink = activ.findViewById(R.id.someHeaderView);
  10. SizeCappedLinearLayout scrollLine = new SizeCappedLinearLayout(activ);
  11. scrollLine.setHeightLink(heightLink);
  12. scrollLine.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
  13. scrollLine.setOrientation(LinearLayout.HORIZONTAL);
  14.  
  15. public class SizeCappedLinearLayout extends LinearLayout {
  16. private View widthLink = null;
  17. private View heightLink = null;
  18.  
  19. public SizeCappedLinearLayout(Context context) {
  20. super(context);
  21. }
  22.  
  23. protected void setWidthLink(View v) {
  24. widthLink = v;
  25. }
  26.  
  27. protected void setHeightLink(View v) {
  28. heightLink = v;
  29. }
  30.  
  31. @Override
  32. protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
  33. if(widthLink != null) {
  34. heightMeasureSpec = getLinkedSpec(widthLink.getMeasuredHeight(), widthLink.getHeight());
  35. }
  36. if(heightLink != null) {
  37. heightMeasureSpec = getLinkedSpec(heightLink.getMeasuredHeight(), heightLink.getHeight());
  38. }
  39. super.onMeasure(widthMeasureSpec, heightMeasureSpec);
  40. }
  41.  
  42. private int getLinkedSpec(int measureDim, int dim) {
  43. if(dim > 0) {
  44. return MeasureSpec.makeMeasureSpec(dim, MeasureSpec.AT_MOST);
  45. } else {
  46. return MeasureSpec.makeMeasureSpec(measureDim, MeasureSpec.AT_MOST);
  47. }
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement