Layout rolável personalizado com valores padrão

Estou tentando criar RelativeLayout personalizado dentro do ScrollView.
Agora eu tenho que copiar esta parte do código em todos os lugares onde eu quero usá-lo:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="xxx"
        android:layout_height="yyy">

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="top"
            android:layout_margin="@dimen/card_margin"
            android:background="@drawable/card_background"
            android:gravity="center"
            android:padding="@dimen/card_padding">

        // content
    </RelativeLayout>
</ScrollView>

Eu gostaria de obter os mesmos resultados com apenas isso:

<MyScrollableRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="xxx"
        android:layout_height="yyy">

    // content
</MyScrollableRelativeLayout>

É possível fazê-lo dessa maneira?

Atualização 1

Eu tentei fazer isso desta maneira:

public class MyScrollableRelativeLayout extends ScrollView {
    private RelativeLayout content;
    int padding;
    int margin;

    public MyScrollableRelativeLayout(Context context) {
        super(context);
        postConstruct();
    }

    public MyScrollableRelativeLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        postConstruct();
    }

    public MyScrollableRelativeLayout(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        postConstruct();
    }

    private void postConstruct() {
        float scale = getResources().getDisplayMetrics().density;
        padding = (int) (5 * scale);
        margin = (int) (20 * scale);

        content = new RelativeLayout(getContext());
        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        layoutParams.setMargins(margin, margin, margin, margin);
        addView(content, layoutParams);
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        setLook();
    }

    private void setLook() {
        setCardBackground();
        setCardPadding();
    }

    private void setCardBackground() {
        content.setBackground(getResources().getDrawable(R.drawable.card_background));
    }

    private void setCardPadding() {
        setPadding(padding, padding, padding, padding);
    }

    @Override
    public void addView(@NonNull View child) {
        if (getChildCount() == 0) {
            super.addView(child);
        } else {
            content.addView(child);
        }
    }

    @Override
    public void addView(@NonNull View child, int index) {
        if (getChildCount() == 0) {
            super.addView(child, index);
        } else {
            content.addView(child, index);    }
    }

    @Override
    public void addView(@NonNull View child, ViewGroup.LayoutParams params) {
        if (getChildCount() == 0) {
            super.addView(child, params);
        } else {
            content.addView(child, params);
        }
    }

    @Override
    public void addView(@NonNull View child, int index, ViewGroup.LayoutParams params) {
        if (getChildCount() == 0) {
            super.addView(child, index, params);
        } else {
            content.addView(child, index, params);
        }
    }
}

Mas o problema no elemento dentro do ScrollableCardRelativeLayout está se substituindo. Como se estivessem ignorandoandroid:layout_* atributo. O que estou fazendo errado?

questionAnswers(1)

yourAnswerToTheQuestion