微调框的背景图片似乎拉长了 [英] Spinner's background image appears stretched
问题描述
我创建了一个带有背景自定义图像的下拉微调器.我已将微调器放置在线性布局中,并且我已使用重量对齐了物品.
I have created a dropdown spinner with a background custom image. I have placed the spinner in a linear layout and I have aligned items using 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>
Java-
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
图标(右侧的图标)显示为拉伸状态.
As you can see the sort by size
icon (icon on right) appears stretched.
我希望它看起来像-
我的代码有什么问题?请帮忙.
What is wrong with my code? Please help.
推荐答案
背景图像占据了所有给定的空间-LinearLayout
宽度的1/3.如果您不希望它拉伸,则可以创建一个可绘制的布局,例如drawable/my_sort_icon
:
The background image takes all the given space - 1/3 of the the LinearLayout
width. If you don’t want it to stretch, you could create a drawable layout, e.g. drawable/my_sort_icon
:
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/ic_action_sort_by_size"
android:tileMode="disabled"
android:gravity="center" />
并将其用作Spinner
中的背景图片:
and use it as a background image in your Spinner
:
<Spinner
android:id="@+id/more"
android:layout_width="0dp"
android:layout_weight="1"
android:background="@drawable/my_sort_icon"
android:layout_height="@dimen/height"/>
这篇关于微调框的背景图片似乎拉长了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!