Как программно добавить оранжевую линию под изображением? - PullRequest
0 голосов
/ 05 августа 2011

Как добавить оранжевую линию под изображением до его показа в галерее?
Я хочу отметить изображение, чтобы оно выделялось на фоне всех остальных.

Я протестировал все виды LayoutParams, но мне нужен совет.
См. Множество объяснений, как это сделать только в XML.
вот мой getView в адаптере

(ОБНОВЛЕНИЕ С РАБОЧИМ РЕШЕНИЕМ, ЕСЛИ НУЖНО ЭТО НУЖНО)
imageViewWithLine - это пользовательский imageView, который имеет логическое значение
для определения, следует ли рисовать линию или нет

public View getView(int position, View convertView, ViewGroup parent) {

    if (convertView == null){

       BitmapFactory.Options bf = new BitmapFactory.Options();
       bf.inSampleSize = 8; 
       Bitmap bitmap = BitmapFactory.decodeFile(files.get(position).getImagePath(),bf);
       ImageViewWithLine imageViewWithLine = new ImageViewWithLine(ctx, null);
       BitmapDrawable b = new BitmapDrawable(getResources(),bitmap);
       imageViewWithLine.setLayoutParams(new Gallery.LayoutParams(80, 70));
       imageViewWithLine.setScaleType(ImageView.ScaleType.FIT_XY);
       imageViewWithLine.setBackgroundResource(GalItemBg);
       imageViewWithLine.setBackgroundDrawable(b);
       convertView = imageViewWithLine;

    }

    if(files.get(position).addLine() == true){
       ((ImageViewWithLine)convertView).setLine(true);
    }else
    ((ImageViewWithLine)convertView).setLine(false);

    return convertView;

    }
}

1 Ответ

2 голосов
/ 05 августа 2011

Вы можете расширить класс ImageView и создать собственное представление. В пользовательском представлении вы можете переопределить onDraw и нарисовать оранжевую линию таким образом.

Обновление:

Это обычная кнопка с оранжевой полосой внизу. Размеры не точны, но это должно дать вам хорошую отправную точку.

public class ButtonWithLine extends Button {

    public ButtonWithLine(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    protected void onDraw(Canvas canvas) {
        Paint paint = new Paint();
        paint.setColor(Color.rgb(255, 125, 0));
        paint.setStyle(Paint.Style.FILL);

        float height = TypedValue.applyDimension(
            TypedValue.COMPLEX_UNIT_DIP, 10, getResources().getDisplayMetrics());

        canvas.drawRect(0, getHeight() - height, getWidth(), getHeight(), paint);

        super.onDraw(canvas);
    }
}
...