膨胀的LinearLayout未填充对话框/匹配父级

时间:2017-06-28 16:27:56

标签: android android-layout dialog

我正在尝试制作一个全屏AlertDialog,但布局会被挤压到屏幕的一部分。我认为LinearLayout会匹配parent,但它会在对话框中留下很多额外的空间。

Screenshot

这是膨胀视图的xml文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:id="@+id/inflatable_quiz_stress"
    android:layout_height="match_parent"
    android:weightSum="30">

    <Button
        android:layout_height="0dp"
        android:minHeight="0dp"
        android:text="x"
        android:layout_width="wrap_content"
        android:layout_gravity="right"
        android:layout_weight="2"
        android:id="@+id/b_checkin_stress_close"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="2"
        android:textSize="16sp"
        android:textColor="@color/dark_gray"
        android:text="Thursday Jan 1"
        android:id="@+id/tv_checkin_stress_date"
        android:gravity="center"
        android:layout_gravity="center"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="5"
        android:textColor="@color/colorPrimaryDark"
        android:textSize="20sp"
        android:layout_gravity="center"
        android:gravity="center"
        android:layout_marginRight="40dp"
        android:layout_marginLeft="40dp"
        android:id="@+id/tv_checkin_stress_question"
        android:text="@string/stress_level_today"/>

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_gravity="center"
        android:layout_weight="7"
        app:srcCompat="@drawable/cal_background_red" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="2"
        android:text="Excited"
        android:textSize="16dp"
        android:id="@+id/tv_checkin_stress_seekfeedback"
        android:gravity="center"/>

    <SeekBar
        android:layout_width="match_parent"
        android:layout_height="0dp"
        style="@style/Widget.AppCompat.SeekBar.Discrete"
        android:layout_weight="4"
        android:max="4"
        android:progress="2"
        android:id="@+id/seekbar_checkin_stress"/>

    <EditText
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="3"
        android:text="@string/explain_if_you_like"/>

    <Button
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="3"
        android:id="@+id/b_checkin_stress_submit"
        android:text="@string/submit"/>

</LinearLayout>

以下是动态扩充布局的代码。此代码位于RecyclerView适配器

final AlertDialog.Builder builder;
builder = new AlertDialog.Builder(context);
rootLayout = (LinearLayout) layoutInflater.inflate(R.layout.inflatable_checkin_stress, null);
AlertDialog alert = builder.create();
                alert.setView(rootLayout);
                alert.setCanceledOnTouchOutside(false);
                alert.show();
                alert.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

0 个答案:

没有答案