【发布时间】:2014-07-08 12:13:28
【问题描述】:
我无法让我的抽屉显示图像,即使它们被设置在抽屉适配器中。文字显示得很好,所以画出来不是问题,只是设置图标而已。
这是适配器的代码:
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if(v==null){
v=LayoutInflater.from(getContext()).inflate(R.layout.drawer_item, null);
}
DrawerPair dp = getItem(position);
TextView description = (TextView) v.findViewById(R.id.drawer_description);
if(description!=null){
description.setText(dp.title);
description.setCompoundDrawables(dp.icon, null, null, null);
}
return v;
}
并且布局如下:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:gravity="right"
android:layout_height="match_parent"
android:orientation="horizontal" >
<TextView
android:id="@+id/drawer_description"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
</LinearLayout>
这就是它的设置方式。图标是png图像:
mDrawerListView.setAdapter(new DrawerAdapter(
getActionBar().getThemedContext(),
R.layout.drawer_item,
new DrawerPair[]{
new DrawerPair("title1",getResources().getDrawable(R.drawable.icon1)),
new DrawerPair("title2",getResources().getDrawable(R.drawable.icon2)),
new DrawerPair("title3",getResources().getDrawable(R.drawable.icon3))
}));
【问题讨论】:
标签: android imageview navigation-drawer listadapter custom-adapter