Фрагмент диалога FEATURE_NO_TITLE уменьшен

Я показываю DialogFragment. Я реализовал это без проблем, пока не решил удалить заголовок с помощью getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);. После этого все сжимается. Вот мои файлы xml и class.

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:background="@color/white"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="@dimen/activity_vertical_margin">

    <TextView
        android:id="@+id/product_name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColor="@color/red"
        android:textSize="20sp"
        android:text="@string/client_name_hint"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="100"
        android:layout_marginTop="@dimen/activity_vertical_margin"
        android:layout_marginBottom="@dimen/activity_vertical_margin"
        android:orientation="horizontal">

        <ImageView
            android:id="@+id/product_image"
            android:layout_width="0dp"
            android:layout_weight="50"
            android:layout_height="match_parent"/>

        <LinearLayout
            android:layout_width="0dp"
            android:layout_weight="50"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <TextView
                android:id="@+id/product_price"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:gravity="center_vertical"
                android:textColor="@color/red"
                android:textSize="30sp"
                android:textStyle="bold"
                android:text="$349.00"/>

            <TextView
                android:id="@+id/product_color"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textStyle="bold"
                android:textSize="20sp"
                android:text="Color: White"/>

        </LinearLayout>

    </LinearLayout>

    <TextView
        android:id="@+id/product_description"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="@dimen/activity_vertical_margin"
        android:background="#aaada9"
        android:text="Text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:clickable="true"
        android:layout_marginTop="@dimen/activity_vertical_margin"
        android:layout_gravity="right"
        android:gravity="center_vertical"
        android:drawableRight="@android:drawable/ic_input_add"
        android:textColor="@color/red"
        android:text="@string/buy"/>

</LinearLayout>




public class ProductsDetailFragment extends DialogFragment {

    public static final String TAG = "products_detail";

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_product_detail, container, false);
        getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
        return view;
    }
}

Что мне не хватает?


person Carlos J    schedule 13.08.2014    source источник
comment
просто установите минимальную ширину макета, тогда все будет в порядке   -  person tyczj    schedule 13.08.2014
comment
Но тогда он всегда будет иметь эту ширину. Я хочу, чтобы фрагмент адаптировался к содержимому, а не имел фиксированную ширину   -  person Carlos J    schedule 13.08.2014
comment
ваша основная ширина макета в любом случае установлена ​​​​на match-parent, поэтому в любом случае она никогда не будет размером ширины/высоты содержимого   -  person tyczj    schedule 13.08.2014
comment
О, но это так! Когда я оставляю заголовок на Dialog, все работает отлично, и размер адаптируется к содержимому, проблема заключается в том, когда я удаляю заголовок. Спасибо за предложение в любом случае   -  person Carlos J    schedule 13.08.2014
comment
У меня точно такая проблема. @CarlosJ, ты когда-нибудь мог правильно с этим справиться?   -  person Nii Laryea    schedule 19.11.2014
comment
@NiiLaryea, к сожалению, мне пришлось использовать фиксированную ширину   -  person Carlos J    schedule 19.11.2014


Ответы (1)


Установите стиль в onCreate(), это поможет мне не сжимать диалог без заголовка.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setStyle(DialogFragment.STYLE_NO_TITLE, android.R.style.Theme_Holo_Light_Dialog_NoActionBar_MinWidth);
}
person dimetil    schedule 01.12.2014