Android 导航抽屉自定义适配器没有';不显示图像

Android 导航抽屉自定义适配器没有';不显示图像,android,imageview,navigation-drawer,listadapter,custom-adapter,Android,Imageview,Navigation Drawer,Listadapter,Custom Adapter,我无法让我的抽屉显示图像,即使它们是在抽屉适配器中设置的。它可以很好地显示文本,因此不需要全部绘制,只需设置图标即可 以下是适配器的代码: public View getView(int position, View convertView, ViewGroup parent) { View v = convertView; if(v==null){ v=LayoutInflater.from(getContext()).inflate(R.layout.draw

我无法让我的抽屉显示图像,即使它们是在抽屉适配器中设置的。它可以很好地显示文本,因此不需要全部绘制,只需设置图标即可

以下是适配器的代码:

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>

在设置为setCompoundDrawables之前,请执行以下代码行,它将正常工作

可绘制可绘制=dp.icon

可拉深立根(0,0,50,50)//例如,我给50,根据你的设计你可以改变

然后像这样设置为文本视图

description.setCompoundDrawables(drawable,null,null,null)


现在它可以正常工作了。

不知道这会有什么不同,但它可以正常工作!谢谢但是,有没有办法在布局中设置此选项?
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))
        }));