Я создал пользовательский фрагмент диалога, но его ширина очень мала. Как я могу увеличить его? Я думал, что установив ширину на 800dp
, макет диалогового окна будет оборачивать содержимое, но ограничивает его шириной по умолчанию.
Вот что я ищу:
Мой xml:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="800dp"
android:layout_height="match_parent"
android:layout_gravity="center">
<com.google.android.material.button.MaterialButton
android:id="@+id/cancel_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cancel"
android:paddingVertical="@dimen/keyline_6"
app:icon="@drawable/ic_arrow_back_black_24dp"
style="@style/MyTheme.Button.TextButton"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toTopOf="@id/terms_condition_header"/>
<com.google.android.material.textview.MaterialTextView
android:id="@+id/terms_condition_header"
android:padding="@dimen/keyline_6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Terms And Conditions"
android:textColor="@color/color_terms_condition_header"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cancel_btn"
android:textAppearance="@style/TextAppearance.MyTheme.Subtitle1"/>
<com.google.android.material.textview.MaterialTextView
android:id="@+id/appCompatTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/keyline_6"
android:textColor="@color/color_terms_condition_header"
android:text="WHAT DRIVES US? Changing up your all-day, every-day, fun-day experience and having a good time doing it."
android:textAppearance="@style/TextAppearance.MyTheme.Subtitle2"
app:layout_constraintBottom_toTopOf="@+id/appCompatTextView2"
app:layout_constraintTop_toBottomOf="@id/terms_condition_header"
app:layout_constraintStart_toStartOf="parent"/>
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/appCompatTextView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingVertical="@dimen/keyline_4"
android:paddingLeft="@dimen/keyline_6"
android:text="Please read, respect and acknowledge the policies listed below:"
android:textAppearance="@style/TextAppearance.MyTheme.Subtitle3"
app:layout_constraintBottom_toTopOf="@+id/terms_condition_container"
app:layout_constraintTop_toBottomOf="@+id/appCompatTextView"
app:layout_constraintStart_toStartOf="parent"/>
<FrameLayout
android:id="@+id/terms_condition_container"
android:layout_width="match_parent"
android:layout_height="0dp"
android:paddingLeft="@dimen/keyline_6"
app:layout_constraintTop_toBottomOf="@id/appCompatTextView2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent">
<include layout="@layout/terms_condition_text"/>
</FrameLayout>
<com.google.android.material.button.MaterialButton
android:id="@+id/accept_terms_button"
style="@style/MyTheme.Button.Secondary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="@color/color_secondary"
android:text="Accept Terms And Conditions"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/terms_condition_container" />
</androidx.constraintlayout.widget.ConstraintLayout>
Диалог класс:
class TermsAndConditionDialogFragment : BaseDialogFragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.dialog_terms_condition, container, false)
return view
}
}
Мой превью:
Заранее благодарю за любую помощь!
1 ответ
Попробуй это
@Override
public void onStart() {
super.onStart();
if (getContext() == null) return;
getDialog().getWindow().setLayout(((int) (0.8 * ScreenUtils.getScreenWidth(getContext()))), ViewGroup.LayoutParams.WRAP_CONTENT);
}
И это для getScreenWidth
public static int getScreenWidth(Context context) {
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics dm = new DisplayMetrics();
windowManager.getDefaultDisplay().getMetrics(dm);
return dm.widthPixels;
}
Похожие вопросы
Новые вопросы
android
Android — это мобильная операционная система Google, используемая для программирования или разработки цифровых устройств (смартфонов, планшетов, автомобилей, телевизоров, одежды, очков, IoT). Для тем, связанных с Android, используйте теги, специфичные для Android, такие как android-intent, android-activity, android-adapter и т. д. Для вопросов, отличных от разработки или программирования, но связанных с Android framework, используйте эту ссылку: https://android .stackexchange.com.