SHARE
TWEET

Untitled

a guest Jun 18th, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top