android – Textview setCompoundDrawables不要改变或显示

android – Textview setCompoundDrawables不要改变或显示,第1张

概述我有一个带有自定义列表项的ListView <?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_hei 我有一个带有自定义列表项的ListVIEw

<?xml version="1.0" enCoding="utf-8"?><linearLayout    xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:layout_wIDth="match_parent"    androID:layout_height="wrap_content"    androID:orIEntation="horizontal" >        <ImageVIEw        androID:ID="@androID:ID/icon"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:contentDescription="@string/app_name"        androID:maxWIDth="32dp" />    <TextVIEw        androID:ID="@androID:ID/Title"        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:layout_gravity="center|left"        androID:paddingBottom="4dp"        androID:paddingtop="4dp"        androID:textIsSelectable="true"        androID:textSize="24sp" >    </TextVIEw></linearLayout>

现在Eclipse警告我这个标签及其子代可以替换为一个< TextVIEw />和一个复合的drawable.一切正常,但我讨厌警告,现在我改变了观点.

<?xml version="1.0" enCoding="utf-8"?><linearLayout    xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:layout_wIDth="match_parent"    androID:layout_height="wrap_content"    androID:orIEntation="horizontal" >    <TextVIEw        androID:ID="@androID:ID/Title"        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:layout_gravity="center|left"        androID:paddingBottom="4dp"        androID:paddingtop="4dp"        androID:textIsSelectable="true"        androID:textSize="24sp"        androID:drawableleft="@drawable/unstarred" >    </TextVIEw></linearLayout>

但是图像没有显示,可以告诉我布局有什么问题,这是我的适配器

public class categoryAdapter extends ArrayAdapter<category> {    private Context mContext;    private int mLayoutResourceID;    private category mCategorIEs[] = null;    public categoryAdapter(Context context,int layoutResourceID,category[] data) {        super(context,layoutResourceID,data);        mContext = context;        mCategorIEs = data;        mLayoutResourceID = layoutResourceID;    }    @OverrIDe    public VIEw getVIEw(int position,VIEw convertVIEw,VIEwGroup parent) {        VIEw row = convertVIEw;        Holder holder = null;        if(null == row) {                           row = LayoutInflater.from(mContext).inflate(mLayoutResourceID,parent,false);            holder = new Holder();            holder.mIcon = (ImageVIEw)row.findVIEwByID(androID.R.ID.icon);            holder.mTitle = (TextVIEw)row.findVIEwByID(androID.R.ID.Title);            row.setTag(holder);        } else {            holder = (Holder) row.getTag();        }       // obvIoUsly only one is used at a time       // First layout       final category category = mCategorIEs[position];       holder.mTitle.setText(category.getname());       holder.mIcon          .setimageResource(category.getStarred() == 1 ? R.drawable.starred : R.drawable.unstarred);                   // Second layout       final category category = mCategorIEs[position];       final Drawable icon = getResources().getDrawable(category.getStarred() == 1 ? R.drawable.starred : R.drawable.unstarred);       holder.mTitle.setText(category.getname());       holder.mTitle.setCompoundDrawables(icon,null,null);        return row;    }       }public static class Holder {    ImageVIEw mIcon;    TextVIEw mTitle;        }

问题是:图像没有显示

解决方法 我为setCompoundDrawablesWithIntrinsicBounds更改了setCompoundDrawables,最后工作 总结

以上是内存溢出为你收集整理的android – Textview setCompoundDrawables不要改变或显示全部内容,希望文章能够帮你解决android – Textview setCompoundDrawables不要改变或显示所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1123463.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存