Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. package com.safepin.app.view.component.customview;
  2.  
  3. import android.content.Context;
  4. import android.content.res.TypedArray;
  5. import android.graphics.Canvas;
  6. import android.support.annotation.NonNull;
  7. import android.util.AttributeSet;
  8. import android.view.View;
  9. import android.view.ViewGroup;
  10. import android.widget.RelativeLayout;
  11. import com.safepin.app.R;
  12.  
  13. public class FixedHeightLayout extends RelativeLayout {
  14.  
  15. private static final double DEFAULT_HEIGHT_FACTOR = 1.3;
  16. private int mFixedHeight;
  17.  
  18. public FixedHeightLayout(Context context, AttributeSet attrs) {
  19. super(context, attrs);
  20. initAttributes(attrs);
  21. }
  22.  
  23. private void initAttributes(AttributeSet attrs) {
  24. TypedArray attrsArray = getContext().obtainStyledAttributes(attrs, R.styleable.FixedHeightLayout);
  25. String fixedHeight = attrsArray.getString(R.styleable.FixedHeightLayout_fixed_height);
  26. try {
  27. mFixedHeight = Integer.parseInt(fixedHeight);
  28. } catch (NumberFormatException e) {
  29. mFixedHeight = (int) (getResources().getDisplayMetrics().heightPixels * DEFAULT_HEIGHT_FACTOR);
  30. }
  31. attrsArray.recycle();
  32. }
  33.  
  34. @Override
  35. protected boolean drawChild(@NonNull Canvas canvas, @NonNull View child, long drawingTime) {
  36. ViewGroup.LayoutParams params = child.getLayoutParams();
  37. params.height = mFixedHeight;
  38. child.setLayoutParams(params);
  39. return super.drawChild(canvas, child, drawingTime);
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement