正如您在我的屏幕截图中看到的那样,虽然它有足够的空间,但整个布局都没有显示在dialogFragment中。我不知道我的错误是什么。
我希望看到一张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;
}
}
它的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"/>
我的适配器类:
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;
}
}
最后,排:
<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>
这是我在设备上看到的屏幕截图:
答案 0 :(得分:1)
试试这个:
在&rbspume()&#39;
中添加以下代码WindowManager.LayoutParams params = getDialog().getWindow().getAttributes();
params.width = LayoutParams.MATCH_PARENT;
params.height = LayoutParams.MATCH_PARENT;
getDialog().getWindow().setAttributes(params);