색상 선택을위한 회 전자를 만들려고합니다. 색상은 Spinner 헤더에 표시되어야합니다. 여기에 스크린 샷입니다 :맞춤형 회 전자 배경
그러나 당신이 볼 수 있듯이, 색상 내 9 패치 스피너 배경 (헤더)를 기입하지 않습니다. 여기에 9 패치 배경입니다 : 여기
spinner = (Spinner) findViewById(R.id.spinner);
ArrayAdapter<String> adapter = new MyArrayAdapter(this, R.layout.spinner_row, R.id.textView1, items);
spinner.setAdapter(adapter);
private class MyArrayAdapter extends ArrayAdapter<String>{
public MyArrayAdapter(Context context, int resource, int textViewResourceId, String[] objects) {
super(context, resource, textViewResourceId, objects);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
return getCustomViewSmall(position, convertView, parent);
}
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
return getCustomView(position, convertView, parent);
}
public View getCustomView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = getLayoutInflater();
View row = inflater.inflate(R.layout.spinner_row, parent, false);
View v = (View) row.findViewById(R.id.spinnerFrame);
v.setBackgroundColor(getColor(position));
return row;
}
public View getCustomViewSmall(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = getLayoutInflater();
View row = inflater.inflate(R.layout.spinner_row_small, parent, false);
row.setBackgroundColor(getColor(position));
return row;
}
private int getColor(int pos) {
switch(pos) {
case 0:
return colors[0]; // Blue
case 1:
return colors[1]; // Purple
case 2:
return colors[2]; // Orange
case 3:
return colors[3]; // Yellow
case 4:
return colors[4]; // Cyan
}
return colors[5];
}
}
그리고 :
는 그러나
내가 정의 ArrayAdapter와 구현 왜 ... 난 이해가 안 돼요, 여기에 코드입니다 레이아웃의 코드 :
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/spinnerFrameSmall"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</FrameLayout>
:
spinner_row_small.xml (즉, 상기 헤더의 배치도이다)
spinner_row.xml (행의 레이아웃) :
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/FrameLayout1"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="center"
android:background="@color/white" >
<FrameLayout
android:id="@+id/spinnerFrame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginBottom="1dp"
android:layout_marginTop="1dp" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
</FrameLayout>
</FrameLayout>
그리고 main.xml에는 : 누군가가 내 도움이 될 수있는 경우
<Spinner
android:id="@+id/spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/textview"
android:spinnerMode="dropdown"
android:popupBackground="@drawable/spinner_background"
android:layout_marginBottom="30dp" />
나는 매우 기뻐할 것입니다.
감사합니다.
이미지에 대한 나쁜 링크. 무결성을 위해 SO 자신의 업로드 기능 사용 –