我正在我的应用程序中创建一个自定义微调器。这些项目可以完美显示,但是问题是列表项没有滚动。
请参考下图。在下图中,我正在使用许多国家/地区,但无法滚动到其他国家/地区选项。
这是我下面完整的微调代码:
main_activity.xml
<android.support.percent.PercentRelativeLayout
android:id="@+id/layoutSpinner"
android:layout_centerHorizontal="true"
android:background="@drawable/bg_spinner_countrycode"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
app:layout_widthPercent="25%">
<Spinner
android:id="@+id/spCountryCode"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.percent.PercentRelativeLayout>
MainActivity.java:
Spinner spCountryCode = (Spinner) findViewById(R.id.spCountryCode);
CountryCodeAdapter countryCodeAdapter = new CountryCodeAdapter(LoginScreenActivity.this, modelList);
spCountryCode.setAdapter(countryCodeAdapter);
CountryCodeAdapter.java:
public class CountryCodeAdapter extends ArrayAdapter<CountryCodeModel> {
Activity activity;
List<CountryCodeModel> itemList;
LayoutInflater inflater;
public CountryCodeAdapter(Activity activity, List<CountryCodeModel> itemList) {
super(activity, R.layout.country_code_spinner_layout, itemList);
this.activity = activity;
this.itemList = itemList;
inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@NonNull
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View itemView = inflater.inflate(R.layout.country_code_spinner_layout, parent, false);
ImageView imgFlag = (ImageView) itemView.findViewById(R.id.imgFlag);
TextView lblCountryName = (TextView) itemView.findViewById(R.id.lblCountryName);
TextView lblCountryCode = (TextView) itemView.findViewById(R.id.lblCountryCode);
Picasso.with(activity).load(itemList.get(position).getStrCountryFlagUrl()).into(imgFlag);
RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) imgFlag.getLayoutParams();
lp.addRule(RelativeLayout.CENTER_IN_PARENT);
imgFlag.setLayoutParams(lp);
//lblCountryName.setText(itemList.get(position).getStrCountryName());
lblCountryName.setVisibility(View.GONE);
//lblCountryCode.setText("(" + itemList.get(position).getStrCountryCode() + ")");
lblCountryCode.setVisibility(View.GONE);
return itemView;
}
@Override
public View getDropDownView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
View itemView = inflater.inflate(R.layout.country_code_spinner_layout, parent, false);
ImageView imgFlag = (ImageView) itemView.findViewById(R.id.imgFlag);
TextView lblCountryName = (TextView) itemView.findViewById(R.id.lblCountryName);
TextView lblCountryCode = (TextView) itemView.findViewById(R.id.lblCountryCode);
Picasso.with(activity).load(itemList.get(position).getStrCountryFlagUrl()).into(imgFlag);
lblCountryName.setText(itemList.get(position).getStrCountryName());
lblCountryCode.setText(itemList.get(position).getStrCountryCode());
return itemView;
}
}
另外,我也尝试过countryCodeAdapter.setDropDownViewResource(R.layout.country_code_spinner_layout);
之前的spCountryCode.setAdapter(countryCodeAdapter);
,但还是没有成功。
此外,如果您想查看我的自定义微调器布局,就是这样。
country_code_spinner_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="@dimen/countryCodeSpinnerDropDownHeight">
<ImageView
android:id="@+id/imgFlag"
android:layout_width="@dimen/countryCodeSpinnerImageSize"
android:layout_height="@dimen/countryCodeSpinnerImageSize"
android:layout_marginLeft="@dimen/countryCodeSpinnerMarginLeft"
android:layout_centerVertical="true"/>
<com.base.silpre.Font_TextViewOpenSans_SemiBold
android:id="@+id/lblCountryName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/imgFlag"
android:layout_centerVertical="true"
android:layout_marginLeft="@dimen/countryCodeSpinnerMarginLeft"
android:textSize="@dimen/countryCodeSpinnerTextsSize"
android:textColor="@android:color/black"/>
<com.base.silpre.Font_TextViewOpenSans_Italic
android:id="@+id/lblCountryCode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/lblCountryName"
android:layout_centerVertical="true"
android:layout_marginLeft="@dimen/countryCodeSpinnerMarginLeft"
android:textSize="@dimen/countryCodeSpinnerTextsSize"
android:textColor="@android:color/black"/>
</RelativeLayout>
如果有人有解决自定义微调器的方法,请还原。
答案 0 :(得分:0)
尝试wrap_content获取高度
dfx['diffx'] = dfx['y']-dfx['x']
dfx['diff'] = dfx['diffx'].apply(lambda x: x.days)
dfx