Skip to content

title divider比title先被add到父view,导致divider显示在title上方(应该显示在下方) #72

Description

@jadepeakpoet
@NonNull
private TextView createTitle() {
    TextView titleView = new TextView(getContext());

    if (mDialogParams.typeface != null) {
        titleView.setTypeface(mDialogParams.typeface);
    }
    titleView.setGravity(Gravity.CENTER);
    titleView.setId(android.R.id.title);
    RelativeLayout.LayoutParams layoutParamsTitle = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    layoutParamsTitle.addRule(RelativeLayout.CENTER_HORIZONTAL);
    titleView.setLayoutParams(layoutParamsTitle);
    if (mTitleParams.height != 0) {
        titleView.setHeight(Controller.dp2px(getContext(), mTitleParams.height));
    }
    titleView.setTextColor(mTitleParams.textColor);
    titleView.setTextSize(mTitleParams.textSize);
    titleView.setText(mTitleParams.text);
    titleView.setTypeface(titleView.getTypeface(), mTitleParams.styleText);

    int[] padding = mTitleParams.padding;
    if (padding != null) {
        if (mTitleParams.isShowBottomDivider) {
            padding[3] = padding[3] == 0 ? padding[1] : padding[3];
            DividerView dividerView = new DividerView(getContext(), LinearLayout.HORIZONTAL);

            // 创建titleView的时候,就对dividerView做了add操作,所以dividerView在Title之前被添加
            addView(dividerView);
        }
        titleView.setPadding(Controller.dp2px(getContext(), padding[0]), Controller.dp2px(getContext(), padding[1]),
                Controller.dp2px(getContext(), padding[2]), Controller.dp2px(getContext(), padding[3]));
    }
    return titleView;
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions