4

BottomSheetDialogFragment にマージンを追加しようとしましたが、マージンに対して何もしません。

ここに画像の説明を入力

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_margin="16dp">

    <TextView
        android:id="@+id/alertdialog_fragmail_newmessage"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Test 1"
        android:textStyle="bold"
        android:padding="16dp"
        android:textColor="@color/colorBlackFont"
        android:layout_alignParentTop="true"
        android:gravity="center_vertical"
        android:drawablePadding="16dp"/>


  //More Textviews

</RelativeLayout>

編集:_________________________________________________________________

XML を以下の回答に変更しようとしましたが、それでもまだ bottomsheetdialogfragment のマージンを作成していません。

Bottom シート ダイアログ フラグメント クラスのコード:

public class FragMailMoreDialog extends BottomSheetDialogFragment {

    private static final String TAG = "FragMailMoreDialog";

    private Context mContext;


    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext = getContext();
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater,
                             @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.alertdialog_layout_fragmailmore, container, false);
        ButterKnife.bind(this, view);


        return view;
    }
}

ボトムシートを膨らませるコード:

private void inflateMoreDialog(){
        FragMailMoreDialog moreDialog = new FragMailMoreDialog();
        if (getFragmentManager() != null) {
            moreDialog.show(getFragmentManager(), "FRAGMAIL_MORE_DIALOG");
        }
    }
4

7 に答える 7

0

Constraint の子にマージンを追加し、親の Constraint の背景を透明にします Bottom Sheet レイアウト イメージ

<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:background="#99000000"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <androidx.constraintlayout.widget.ConstraintLayout
        style="@style/BottomSheetDialogStyle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="@dimen/margin_medium"
        android:layout_marginEnd="@dimen/margin_medium"
        android:orientation="vertical"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent">

        <androidx.appcompat.widget.AppCompatImageView
            android:id="@+id/iv_add_post_ic"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="@dimen/margin_medium"
            android:layout_marginTop="@dimen/margin_form"
            android:layout_marginBottom="@dimen/margin_small"
            android:src="@drawable/ic_add_post"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <androidx.appcompat.widget.AppCompatTextView
            android:id="@+id/tv_add_post"
            style="@style/Widget.nejmo.Text.Medium"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/margin_form"
            android:layout_marginHorizontal="@dimen/margin_small"
            android:layout_marginStart="@dimen/margin_small"
            android:layout_marginBottom="@dimen/margin_small"
            android:text="@string/option_add_post_txt"
            android:textColor="@color/dusk"
            app:layout_constraintBottom_toBottomOf="@+id/iv_add_post_ic"
            app:layout_constraintStart_toEndOf="@+id/iv_add_post_ic"
            app:layout_constraintTop_toTopOf="@+id/iv_add_post_ic" />


        <androidx.appcompat.widget.AppCompatImageView
            android:id="@+id/iv_add_question_ic"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="@dimen/margin_medium"
            android:layout_marginTop="@dimen/margin_medium"
            android:layout_marginBottom="@dimen/margin_medium"
            android:src="@drawable/ic_add_question"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/iv_add_post_ic" />

        <androidx.appcompat.widget.AppCompatTextView
            android:id="@+id/tv_add_question"
            style="@style/Widget.nejmo.Text.Medium"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/margin_form"
            android:layout_marginHorizontal="@dimen/margin_small"
            android:layout_marginStart="@dimen/margin_small"
            android:layout_marginTop="@dimen/margin_medium"
            android:layout_marginBottom="@dimen/margin_medium"
            android:text="@string/option_add_question_txt"
            android:textColor="@color/dusk"
            app:layout_constraintBottom_toBottomOf="@+id/iv_add_question_ic"
            app:layout_constraintStart_toEndOf="@+id/iv_add_question_ic"
            app:layout_constraintTop_toTopOf="@+id/iv_add_question_ic" />

    </androidx.constraintlayout.widget.ConstraintLayout>

</androidx.constraintlayout.widget.ConstraintLayout>
于 2021-05-26T13:47:36.723 に答える
0

BottomSheetDialogFragment のマージンが必要な理由がわかりません。これは、Activity/Fragment の上に表示される DialogFragment です。それにマージンを追加しても何も起こりません。必要なものが TextView (Test1) の上部のパディングと TextView (Test2) の下部のパディングである場合、次のように Test1 に padding_top を追加し、Test2 に padding_bottom を追加する必要があります。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_margin="16dp">

    <TextView
        android:id="@+id/alertdialog_fragmail_newmessage"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Test 1"
        android:textStyle="bold"
        android:paddingTop="32dp"
        android:paddingStart="16dp"
        android:paddingEnd="16dp"
        android:paddingBottom="16dp"
        android:textColor="@color/colorBlackFont"
        android:layout_alignParentTop="true"
        android:gravity="center_vertical"
        android:drawablePadding="16dp"/>
</RelativeLayout>
于 2020-03-14T05:58:33.933 に答える