我想这张照片可以解释一切。当然,您可以增加 DialogFragment 的大小,但也许您可以做不同的事情?他们让我附上代码,我附上标记
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".view.dialogFragment.FilterDialog3"
android:orientation="vertical"
android:minWidth="500dp"
android:minHeight="200dp"
android:background="@color/background"
android:padding="10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Жанры"
android:focusable="false"
android:textColor="@color/white3"
android:layout_gravity="center"
android:gravity="center"/>
<com.jaredrummler.materialspinner.MaterialSpinner
android:id="@+id/spinGenres"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/item_chanel"
android:focusableInTouchMode="true"
app:ms_background_color="@color/gray_spiner"
app:ms_background_selector="@drawable/material_spinner_selector"
android:focusable="true"
app:ms_dropdown_height="wrap_content"
app:ms_dropdown_max_height="350dp"
android:nextFocusDown="@id/spinCountries"
android:textColor="@color/white3"
android:layout_gravity="center"
android:gravity="center"
>
<requestFocus/>
</com.jaredrummler.materialspinner.MaterialSpinner>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Страны"
android:focusable="false"
android:textColor="@color/white3"
android:layout_gravity="center"
android:gravity="center"/>
<com.jaredrummler.materialspinner.MaterialSpinner
android:id="@+id/spinCountries"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background_"
android:focusableInTouchMode="true"
app:ms_background_color="@color/gray_spiner"
app:ms_background_selector="@drawable/material_spinner_selector"
android:focusable="true"
app:ms_dropdown_height="wrap_content"
app:ms_dropdown_max_height="350dp"
android:nextFocusDown="@id/spinYears"
android:nextFocusUp="@id/spinGenres"
android:textColor="@color/white3"
android:layout_gravity="center"
android:gravity="center"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Годы"
android:textColor="@color/white3"
android:layout_gravity="center"
android:gravity="center"/>
<com.jaredrummler.materialspinner.MaterialSpinner
android:id="@+id/spinYears"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background_"
android:focusableInTouchMode="true"
app:ms_background_color="@color/gray_spiner"
app:ms_background_selector="@drawable/material_spinner_selector"
android:focusable="true"
app:ms_dropdown_height="wrap_content"
app:ms_dropdown_max_height="350dp"
android:nextFocusUp="@id/spinCountries"
android:textColor="@color/white3"
android:layout_gravity="center"
android:gravity="center"/>
</LinearLayout>
DialogFragment 本身:
public class FilterDialog3 extends DialogFragment implements FilterView {
@BindView(R.id.spinGenres)
MaterialSpinner spinGenres;
@BindView(R.id.spinCountries)
MaterialSpinner spinCountries;
@BindView(R.id.spinYears)
MaterialSpinner spinYears;
FilterPresenter presenter;
List<String> years;
List<String> countries ;
List<String> genres;;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
presenter = new FilterPresenter();
presenter.onCreate(this);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View v = inflater.inflate(R.layout.fragment_dialog3, container, false);
ButterKnife.bind(this, v);
return v;
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
presenter.getgenres();
presenter.getcountries();
presenter.getyears();
spinGenres.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
//spinGenres.expand();
spinGenres.setBackground(getActivity().getResources().getDrawable(R.drawable.border));
} else {
spinGenres.setBackground(getActivity().getResources().getDrawable(R.color.background_));
}
}
});
spinYears.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
//spinYears.expand();
spinYears.setBackground(getActivity().getResources().getDrawable(R.drawable.border));
} else {
spinYears.setBackground(getActivity().getResources().getDrawable(R.color.background_));
}
}
});
spinCountries.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
//spinCountries.expand();
spinCountries.setBackground(getActivity().getResources().getDrawable(R.drawable.border));
} else {
spinCountries.setBackground(getActivity().getResources().getDrawable(R.color.background_));
}
}
});
spinGenres.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
L.i("spinGenres is working yraaa!!!!!!!!!!!!!!");
if (event.getAction() == KeyEvent.ACTION_UP){
if(keyCode == KeyEvent.KEYCODE_ENTER) {
spinGenres.expand();
spinGenres.setBackground(getActivity().getResources().getDrawable(R.drawable.border));
}
}
return false;
}
});
}
@Override
public void setYears(List<ResultYear> years) {
this.years = new ArrayList<>();
for(ResultYear ry : years) {
for(String ry2 : ry.getYear()) {
this.years.add(ry2);
}
}
spinYears.setItems(this.years);
}
@Override
public void setGenres(List<ResultGenre> genres) {
this.genres = new ArrayList<>();
for(ResultGenre ry : genres) {
for(String ry2 : ry.getGenres()) {
this.genres.add(ry2);
}
}
spinGenres.setItems(this.genres);
focusFilter(spinGenres);
}
@Override
public void setCountries(List<ResultCountry> countries) {
this.countries = new ArrayList<>();
for(ResultCountry ry : countries) {
for(String ry2 : ry.getCountry()) {
this.countries.add(ry2);
}
}
spinCountries.setItems(this.countries);
}
public void focusFilter(MaterialSpinner spin) {
spin.requestFocus();
spin.setActivated(true);
}
}

他们正确地告诉我,可能问题出在库中,或者无论如何我做错了什么,我将 MaterialSpinner 更改为 Spinner 并停止剪辑: