在Android中旋转旋转箭头180

时间:2014-05-12 11:37:47

标签: android android-layout android-spinner android-ui

问题: 我需要为RTL语言实现Spinner,使文本向左和向下箭头对齐。我能够实现这种对齐,但箭头指向上方。 我不想使用setRotation,因为它只能从API级别11获得。 PFB我正在使用的代码:

    //Creating spinner
    Spinner s=new RTLSpinner(this);
    List<String> list = new ArrayList<String>();
    list.add("list 1");
    list.add("list 2");
    list.add("list 3");
    ArrayAdapter<String> dataAdapter = new CustomAdapter(this, android.R.layout.simple_spinner_item, list);
    dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    s.setAdapter(dataAdapter);

    //Fetching the background drawable of Spinner
    NinePatchDrawable drawable=(NinePatchDrawable)(((StateListDrawable)s.getBackground()).getCurrent());

    //Converting it into Bitmap
     Bitmap bmpOriginal = Bitmap  
             .createBitmap(  
                     drawable.getIntrinsicWidth(),  
                     drawable.getIntrinsicHeight(),  
                     drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888  
                             : Bitmap.Config.RGB_565);  
     Canvas canvas = new Canvas(bmpOriginal);  
     drawable.setBounds(0, 0, drawable.getIntrinsicWidth(),  
             drawable.getIntrinsicHeight());  
     drawable.draw(canvas);

     //Rotating the image
     Bitmap bmResult = Bitmap.createBitmap(bmpOriginal.getWidth(), bmpOriginal.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas tempCanvas = new Canvas(bmResult); 
    tempCanvas.rotate(180, bmpOriginal.getWidth()/2, bmpOriginal.getHeight()/2);
    tempCanvas.drawBitmap(bmpOriginal, 0, 0, null);
    s.setBackgroundDrawable(new BitmapDrawable(bmResult));


   class CustomAdapter extends ArrayAdapter<String> {

    public CustomAdapter(Context context, int textViewResourceId,
            List<String> textArray) {
        super(context, textViewResourceId, textArray);
    }

    public TextView getView(int position, View convertView, ViewGroup parent) {
        TextView viewObj = (TextView) super.getView(position, convertView,
                parent);
        TextView optionView = (TextView) viewObj
                .findViewById(android.R.id.text1);
        optionView.setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL);
        return viewObj;
    }
}

提前致谢!

0 个答案:

没有答案