일반 오래된 Android 버튼의 Compound Drawable에 선을 그리려합니다. Button.getCompoundDrawables()[1]
을 사용하여 버튼의 드로어 블 (drawable)을 얻으려는 것으로 시작했지만 선은 결코 나타나지 않습니다. 그래서, 나는 버튼에 복합 드로어 블을위한 XML 레이아웃에 실제 이미지를 넣었습니다. OK (사진의 주황색 사각형)가 작동하지만 전화가 회전하면 주황색 사각형의 크기가 조절되지 않고 버튼이 제대로 작동하지 않으므로 결국 너무 크게됩니다. 교대 또는 무언가를 할 때 getBounds()
으로 전화해야합니까?Android 컴파운드 드로어로 그리기
드로어 블에 어떤 크기 조정이 적용되어야합니다. 알아 차릴 경우 빨간색 선은 가로 방향 모서리로 이동하지만 세로 방향 모퉁이로 이동하지 않아야합니다. 꺼져 있거나 뭔가 있어요. 주황색 사각형은 드로어 블 - [lhm] dpi/디렉토리에서 다른 크기로 존재하지만 가로 및 세로에 대해 두 개의 개별 레이아웃이 없습니다. 선을 그리기위한
코드 : 그것은 다른 사람을 도움이 경우
@Override
public View getView (int position, View convertView, ViewGroup parent)
{
View row = convertView;
if (row == null)
{
LayoutInflater inflater = (LayoutInflater) _context.getSystemService (Context.LAYOUT_INFLATER_SERVICE);
row = inflater.inflate (R.layout.monthview, parent, false);
}
btn_cell = (Button) row.findViewById (R.id.bcell);
...
BitmapDrawable btn_draw = (BitmapDrawable) btn_cell.getCompoundDrawables()[1];
if (btn_draw != null)
{
Log.d (TAG, "+++++++++++++ drawing line");
Bitmap btn_bmp = btn_draw.getBitmap();
Bitmap offscreen_bmp = Bitmap.createBitmap(btn_bmp.getWidth(), btn_bmp.getHeight(), btn_bmp.getConfig());
BitmapDrawable offscreen_draw = new BitmapDrawable (offscreen_bmp);
offscreen_draw.setBounds (btn_draw.getBounds());
Canvas c = new Canvas(offscreen_bmp);
// draw line
Paint p = new Paint();
p.setAntiAlias(true);
p.setStrokeWidth(1);
p.setStyle(Style.FILL_AND_STROKE);
p.setColor(Color.RED);
c.drawBitmap (btn_bmp, 0, 0, p);
c.drawLine (0, 0, offscreen_bmp.getWidth(), offscreen_bmp.getHeight(), p);
(R.drawable.cal_left_arrow_off), null, null);
btn_cell.setCompoundDrawables(null, offscreen_draw, null, null);
}
, 나는 같은 많은으로하여 ImageButton의 서브 클래스 결국 나는 원래 의도했던 것을 성취하기 위해 여기에 제시된 방법대로 – wufoo