0
正如您在我的屏幕截圖中看到的,雖然它具有足夠的空間,但整個佈局不會顯示在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>
這是截圖我在我的設備上查看:
我知道它已經有一段時間內將下面的代碼,但你有沒有發現,並回答您的問題? –