DialogFragment onCreateView无法显示所有视图

时间:2012-03-29 01:57:24

标签: android dialog

我的DialogFragment中有一个onCreateView方法,如下所示:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.purchase_dialog, container, false);
    int title = getArguments().getInt("title");
    String titleString = getResources().getString(title);
    getDialog().setTitle(titleString);

    final TextView currentOfferPrice = (TextView) v.findViewById(R.id.current_offer_price);
    final SeekBar editPurchasePrice = (SeekBar) v.findViewById(R.id.purchase_price);
    editPurchasePrice
            .setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

                @Override
                public void onStopTrackingTouch(SeekBar seekBar) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void onStartTrackingTouch(SeekBar seekBar) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void onProgressChanged(SeekBar seekBar,
                        int progress, boolean fromUser) {
                    currentOfferPrice.setText("You offer $"
                            + editPurchasePrice.getProgress());
                }
            });
    editPurchasePrice.setMax(((Purchase)getActivity()).getTotal());
    final DisplayHouse house = ((Purchase)getActivity()).getHouse();
    editPurchasePrice.setProgress(house.getMarketPrice());
    currentOfferPrice.setText("You offer $"
            + editPurchasePrice.getProgress());
    final Button btnOffer = (Button) v.findViewById(R.id.btn_offer);
    btnOffer.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            final DisplayHouse house = ((Purchase)getActivity()).getHouse();
            Log.d("log", "current market price: " + house.getMarketPrice());
            final int offerPrice = editPurchasePrice.getProgress();
            if (offerPrice >= house.getMarketPrice() * 0.999) {
                editPurchasePrice.setProgress(offerPrice);
                ((Purchase)getActivity()).showAcceptDialog();
                PortfolioManager.addHousePortfolio(house, offerPrice);
                Log.d("log", "added a new house to portfolio.");
            } else {
                editPurchasePrice.setProgress(offerPrice);
                ((Purchase)getActivity()).showRejectDialog();
            }
            getDialog().dismiss();
        }
    });

    final Button btnCancel = (Button) v
            .findViewById(R.id.btn_purchase_dialog_cancel);
    btnCancel.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            getDialog().dismiss();
        }
    });

    return v;
}

但奇怪的是,当我打开对话框时,它只显示SeekBar。我看不到TextViews和按钮。我怎样才能让他们展示?

我的布局文件是这样的:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/purchase_dialog"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >

<RelativeLayout 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
<SeekBar
    android:id="@+id/purchase_price"
    android:layout_width="200dip"
    android:layout_height="wrap_content"
    android:inputType="number" 
    android:gravity="center_horizontal"
    android:layout_alignParentRight="true">

</SeekBar>
<TextView
    android:id="@+id/purchasing_text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="#FFF" 
    android:textSize="20dip"
    android:gravity="center_horizontal"
    android:layout_toLeftOf="@id/purchase_price"
    android:text="@string/purchasing_text"
    />
</RelativeLayout>
<TextView 
    android:id="@+id/current_offer_price"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textSize="20dip"
    android:gravity="center_vertical|center_horizontal"
/>
<RelativeLayout 
    android:id="@+id/layout_buttons"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
<Button 
    android:id="@+id/btn_offer"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:text="@string/offer"/>
<Button 
    android:id="@+id/btn_purchase_dialog_cancel"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toLeftOf="@id/btn_offer"
    android:text="@string/cancel"/>
</RelativeLayout>
</LinearLayout>

1 个答案:

答案 0 :(得分:0)

我已经尝试了你的代码,似乎这个

android:layout_height="fill_parent"
第一个RelativeLayout的

隐藏了您的其他视图。

我已经尝试将其更改为50dp,对话框工作正常。