Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.safepin.app.view.component.customview;
- import android.content.Context;
- import android.content.res.TypedArray;
- import android.graphics.Canvas;
- import android.support.annotation.NonNull;
- import android.util.AttributeSet;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.RelativeLayout;
- import com.safepin.app.R;
- public class FixedHeightLayout extends RelativeLayout {
- private static final double DEFAULT_HEIGHT_FACTOR = 1.3;
- private int mFixedHeight;
- public FixedHeightLayout(Context context, AttributeSet attrs) {
- super(context, attrs);
- initAttributes(attrs);
- }
- private void initAttributes(AttributeSet attrs) {
- TypedArray attrsArray = getContext().obtainStyledAttributes(attrs, R.styleable.FixedHeightLayout);
- String fixedHeight = attrsArray.getString(R.styleable.FixedHeightLayout_fixed_height);
- try {
- mFixedHeight = Integer.parseInt(fixedHeight);
- } catch (NumberFormatException e) {
- mFixedHeight = (int) (getResources().getDisplayMetrics().heightPixels * DEFAULT_HEIGHT_FACTOR);
- }
- attrsArray.recycle();
- }
- @Override
- protected boolean drawChild(@NonNull Canvas canvas, @NonNull View child, long drawingTime) {
- ViewGroup.LayoutParams params = child.getLayoutParams();
- params.height = mFixedHeight;
- child.setLayoutParams(params);
- return super.drawChild(canvas, child, drawingTime);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement