SetAlpha在棒棒糖中查看背景不起作用

时间:2015-01-06 20:26:08

标签: java android imageview android-5.0-lollipop android-cardview

我正在开发一个具有背景照片的Android应用程序 所以我决定让我的listView或recyclerView透明以显示这些背景 除了在棒棒糖版本上,每件事情都很好!

this is lollipop version looks like this is kitkat version looks like

我想像所有以前的版本一样制作棒棒糖版本,比如kitkat 这是我用来设置每个项目的透明度的代码片段

@Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder mHolder;
        if (convertView == null) {
            LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.dairy_item, parent, false);
            CardView listItem = (CardView) convertView.findViewById(R.id.dairy_card);
            listItem.setCardElevation(5);
            listItem.setUseCompatPadding(true);
            // listItem.setPadding(0, 0, 5, 6);
            listItem.setPreventCornerOverlap(true);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
                Drawable mBackground = listItem.getBackground();
                mBackground.setAlpha(127);
                listItem.setBackground(mBackground);
            } else {
                listItem.getBackground().setAlpha(127);
            }
            mHolder = new ViewHolder();
            mHolder.typeIcon = (ImageView) convertView.findViewById(R.id.reminder_icon);
            mHolder.title = (TextView) convertView.findViewById(R.id.reminder_identifier);
            mHolder.subtitle = (TextView) convertView.findViewById(R.id.reminder_status);
            mHolder.time = (TextView) convertView.findViewById(R.id.item_time);
            mHolder.order = (TextView) convertView.findViewById(R.id.item_order);
            convertView.setTag(mHolder);
        } else
            mHolder = (ViewHolder) convertView.getTag();

        mHolder.typeIcon.setImageResource(imgRec[position]);
        mHolder.title.setText(title[position]);
        mHolder.subtitle.setText(subtitle[position]);
        String orders = String.valueOf(position + 1);
        if (SettingsFragment.isArabic(mContext))
            orders = Referances.ArabtizeDigits(mContext, orders);
        mHolder.order.setText(orders);
        mHolder.time.setText(time[position]);

        return convertView;
    } 

来自我自己的listView适配器。 提前谢谢....

0 个答案:

没有答案