简体   繁体   English

自定义对话框片段未显示全部视图

[英]Custom Dialog Fragment doesn't show whole of view

As you can see in my screenshot, whole of layout doesn't display in dialogFragment although it has enough space. 如您在我的屏幕快照中所见,尽管有足够的空间,整个布局不会显示在dialogFragment中。 I have no idea what is my mistake. 我不知道我的错误是什么。

I expect to see a 3 * 3 table. 我希望看到3 * 3的桌子。

public class ChangeFormationDialogFragment extends DialogFragment {

    public ChangeFormationDialogFragment() {
        // Empty constructor required for DialogFragment
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        Dialog dialog = super.onCreateDialog(savedInstanceState);

        // request a window without the title
        dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);

        return dialog;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_change_formation, container);

        GridView gridView = (GridView) view.findViewById(R.id.formation_change_grid);
        gridView.setAdapter(new FormationAdapter(getActivity(), 0));

        return view;
    }
}

It's xml file (fragment_change_formation): 它是xml文件(fragment_change_formation):

<GridView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/myTem_bg_boost_cards"
    android:id="@+id/formation_change_grid"
    android:numColumns="auto_fit"
    android:gravity="center"
    android:columnWidth="100dp"
    android:stretchMode="columnWidth"/>

My adapter class: 我的适配器类:

public class FormationAdapter extends BaseAdapter {

    private static final String TAG = "FormationAdapter";

    private Context mContext;
    private ArrayList<String> formations;
    private int selected = 0;

    public FormationAdapter(Context context, int selected) {
        this.mContext = context;

        formations = Formation.getAllFormationsAsArrayOfStrings();
        this.selected = selected;
    }

    @Override
    public int getCount() {
        if(formations == null)
            return 0;

        return formations.size();
    }

    @Override
    public Integer getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;

        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.row_formation, null);
        }

        holder = new ViewHolder();
        holder.llFormation = (LinearLayout) convertView.findViewById(R.id.llFormation);
        holder.llFormationViews = (LinearLayout) convertView.findViewById(R.id.llFormationViews);
        holder.tvFormation = (AnyTextView) convertView.findViewById(R.id.tvFormation);
        holder.tvBuyButton = (AnyTextView) convertView.findViewById(R.id.tvBuyButton);


        holder.tvFormation.setText(formations.get(position));

        if(position > 2)
            holder.tvBuyButton.setVisibility(View.VISIBLE);

        if(position == selected)
            holder.llFormation.setBackgroundColor(mContext.getResources().getColor(R.color.myTeam_greenDark));
        else
            holder.llFormation.setBackgroundColor(mContext.getResources().getColor(R.color.transparent));

        return convertView;
    }

    static class ViewHolder {
        LinearLayout llFormation;
        LinearLayout llFormationViews;
        AnyTextView tvFormation;
        AnyTextView tvBuyButton;
    }
}

And finally, row: 最后,行:

<LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:custom="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:padding="10dp"
        android:id="@+id/llFormation">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:id="@+id/llFormationViews">

        </LinearLayout>

        <com.allstarxi.widget.AnyTextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/tvFormation"
            android:layout_gravity="center"
            style="@style/font_normal_20.white"
            custom:typeface="baltomobilebold.ttf"/>

        <com.allstarxi.widget.AnyTextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/tvBuyButton"
            android:text="@string/myTeam_dialog_buy"
            android:layout_gravity="center"
            android:paddingTop="8dp"
            android:paddingBottom="8dp"
            android:paddingLeft="20dp"
            android:paddingRight="20dp"
            android:background="@color/myTem_bg_points"
            android:textStyle="bold"
            android:visibility="gone"
            style="@style/font_normal_14.black"
            custom:typeface="baltomobilebook.ttf"/>

    </LinearLayout>

This is screenshot of what I see on my device: 这是我在设备上看到的屏幕截图: 在此处输入图片说明

Just try this: 尝试一下:

Add the following code inside 'onResume()' 在“ onResume()”中添加以下代码

WindowManager.LayoutParams params = getDialog().getWindow().getAttributes();
    params.width = LayoutParams.MATCH_PARENT;
    params.height =  LayoutParams.MATCH_PARENT;
    getDialog().getWindow().setAttributes(params);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM