背景のカスタム イメージを使用してドロップダウン スピナーを作成しました。スピナーを線形レイアウトに配置し、weight を使用してアイテムを整列させました。
ここに私のコードがあります -
XML -
<LinearLayout
android:id="@+id/csbar"
android:windowSoftInputMode="adjustPan"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:background="#101010"
android:layout_height="wrap_content">
<ImageButton
android:id="@+id/run"
android:layout_width="0dp"
android:layout_height="@dimen/height"
android:layout_weight="1"
android:background="@null"
android:contentDescription="@string/nul"
android:src="@drawable/ic_action_play" />
<ImageButton
android:id="@+id/save"
android:layout_width="0dp"
android:layout_height="@dimen/height"
android:layout_weight="1"
android:background="@null"
android:contentDescription="@string/nul"
android:src="@drawable/ic_action_save" />
<Spinner
android:id="@+id/more"
android:layout_width="0dp"
android:layout_weight="1"
android:background="@drawable/ic_action_sort_by_size"
android:layout_height="@dimen/height"/>
</LinearLayout>
ジャワ -
int firstC = 0;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
/////I have removed rest of the code to make it more legible/////
Spinner more = (Spinner) rootView.findViewById(R.id.more);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(),
R.array.more, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
more.setAdapter(adapter);
more.setOnItemSelectedListener(this);
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position,
long id) {
((TextView)view).setText(null);
}
出力は次のとおりです-
ご覧のとおり、sort by size
アイコン (右のアイコン) が引き伸ばされて表示されます。
どのように見せたいか -
コードの何が問題になっていますか? 助けてください。