Advertisement
Guest User

Untitled

a guest
Sep 30th, 2014
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.61 KB | None | 0 0
  1. public class CustomView extends FrameLayout {
  2.  
  3. private TextView nameView;
  4. private TextView emailView;
  5. private ImageView addressView;
  6. private Tracks track ;
  7. private double scrollProgress = 0.0;
  8. private double topViewScaleFactor = 2.0;
  9. private double collapsedViewHeight = 200.0;
  10. private double expandedViewHeight = 700.0;
  11. private double scrollProgressPerView = expandedViewHeight;
  12.  
  13. View v;
  14. View firstItem;
  15. View secondView;
  16.  
  17.  
  18. int itemMinHeight = 200;
  19. int itemMaxHeight = 700;
  20.  
  21. public CustomView(MyScrollView paramEventListView, Context paramContext){
  22.  
  23. super(paramContext);
  24. }
  25.  
  26.  
  27.  
  28. public CustomView(Context context) {
  29. super(context);
  30. // TODO Auto-generated constructor stub
  31.  
  32. }
  33.  
  34.  
  35. public CustomView(Context context, AttributeSet attrs, int defStyle) {
  36. super(context, attrs, defStyle);
  37. // TODO Auto-generated constructor stub
  38.  
  39. }
  40.  
  41.  
  42. public CustomView(Context context, AttributeSet attrs) {
  43. super(context, attrs);
  44. // TODO Auto-generated constructor stub
  45.  
  46. }
  47.  
  48. @Override
  49. protected void onLayout(boolean changed, int l, int t, int r, int b) {
  50. // TODO Auto-generated method stub
  51. int m = getMeasuredWidth();
  52.  
  53.  
  54. int itemWidth = (r-l)/getChildCount();
  55. // int itemHeight = (b-t)/getChildCount();
  56.  
  57.  
  58. firstItem = getChildAt(0);
  59. //firstItem.layout(0, 0, r-l, itemMaxHeight);
  60. firstItem.measure(View.MeasureSpec.makeMeasureSpec(m, MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(itemMaxHeight, MeasureSpec.EXACTLY));
  61. firstItem.layout(0, 0, r-l, itemMaxHeight);
  62.  
  63. secondView = getChildAt(1);
  64. secondView.measure(View.MeasureSpec.makeMeasureSpec(m, MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(itemMinHeight, MeasureSpec.EXACTLY));
  65. secondView.layout(0, itemMaxHeight, r-l, itemMinHeight+itemMaxHeight);
  66.  
  67. int FirstAndSEcondItemHeight = firstItem.getHeight() + secondView.getHeight();
  68. for(int i=2; i< this.getChildCount(); i++){
  69. v = getChildAt(i);
  70. // v.layout(itemWidth*i, 0, (i+1)*itemWidth, b-t);
  71.  
  72. v.layout(0, FirstAndSEcondItemHeight + (itemMinHeight*(i-2)), r-l, FirstAndSEcondItemHeight + ((i-1)*itemMinHeight));
  73. }
  74.  
  75.  
  76. }
  77.  
  78.  
  79. @Override
  80. protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
  81. // TODO Auto-generated method stub
  82. super.onMeasure(widthMeasureSpec, heightMeasureSpec);
  83.  
  84.  
  85.  
  86. int heightMeasured = 0;
  87. /*for each child get height and
  88. heightMeasured += childHeight;*/
  89. for(int i=0; i< this.getChildCount(); i++){
  90. heightMeasured += getChildAt(i).getHeight();
  91. }
  92.  
  93. //If I am in a scrollview i got heightmeasurespec == 0, so
  94. if(heightMeasureSpec == 0){
  95. heightMeasureSpec = MeasureSpec.makeMeasureSpec(heightMeasured, MeasureSpec.EXACTLY);
  96. }
  97.  
  98. setMeasuredDimension(getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec), getDefaultSize(this.getSuggestedMinimumHeight(), heightMeasureSpec));
  99. }
  100.  
  101. public class MyScrollView extends ScrollView{
  102.  
  103.  
  104.  
  105. public MyScrollView(Context context) {
  106. super(context);
  107.  
  108. }
  109.  
  110. public MyScrollView(Context context, AttributeSet attrs, int defStyle) {
  111. super(context, attrs, defStyle);
  112. add(context);
  113. }
  114.  
  115. public MyScrollView(Context context, AttributeSet attrs) {
  116. super(context, attrs);
  117. }
  118.  
  119. public void setScrollViewListener(ScrollViewListener scrollViewListener) {
  120. this.scrollViewListener = scrollViewListener;
  121.  
  122.  
  123. }
  124. @Override
  125. protected void onScrollChanged(int x, int y, int oldx, int oldy) {
  126. super.onScrollChanged(x, y, oldx, oldy);
  127.  
  128. // How can I acces to each child in the customView class, and change their height depending on the scrollChanged
  129.  
  130.  
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement