在Android中将许多图片裁剪为圆圈

时间:2013-07-24 14:43:21

标签: android custom-component android-listfragment navigation-drawer

遇到问题我无法解决它:我想裁剪来自ListFragment的许多图片。代码将更明确:

String[] countries = new String[] {
    "Amel Mahmuzić",
    "Laurent Meyer",
    "Philipp Bellé",
    "Dennis Pagano",
    "Bill Gates",
    "Steve Jobs",
    "Jean Bonnot",
    "Nicolas Sarkozy",
    "Bob Marley",
    "Thomas Pieronczyk"
};

int[] flags = new int[]{
    R.drawable.amel_mahmuzic,
    R.drawable.laurent,
    R.drawable.phillip_belle,
    R.drawable.dennis_pagano,
    R.drawable.bill_gates,
    R.drawable.steve_jobs,
    R.drawable.jean_bonnot,
    R.drawable.nicolas_sarkozy,
    R.drawable.bob_marley,
    R.drawable.thomas_pieronczyk,
};

String[] currency = new String[]{
    "MoID GmbH",
    "MoID GmbH",
    "MoID GmbH",
    "MoID GmbH",
    "Microsoft",
    "Apple",
    "Pôle Emploi",
    "Elysée",
    "Weed Fabric",
    "MoID GmbH"
};

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {

    // Each row in the list stores country name, currency and flag
    List<HashMap<String,String>> aList = new ArrayList<HashMap<String,String>>();

    for(int i=0;i<10;i++){
        HashMap<String, String> hm = new HashMap<String,String>();
        hm.put("txt", countries[i]);
        hm.put("cur", currency[i]);
        hm.put("flag", Integer.toString(flags[i]) );
        aList.add(hm);
    }

    // Keys used in Hashmap
    String[] from = { "flag","txt","cur" };

    // Ids of views in listview_layout
    int[] to = { R.id.flag,R.id.txt,R.id.cur};

    // Instantiating an adapter to store each items
    // R.layout.listview_layout defines the layout of each item
    SimpleAdapter adapter = new SimpleAdapter(getActivity().getBaseContext(), aList, R.layout.image_item, from, to);

    setListAdapter(adapter);

    return super.onCreateView(inflater, container, savedInstanceState);
}

}

好的,我知道你在说什么:“它不是旗帜,不是货币......”来自互联网和工作的例子。我只是想知道如何将我的图片裁剪成一个圆圈。

如果没有人发现,是否有人知道如何使用正方形和透明圆圈进行叠加,其颜色在点击时会发生变化?

如果你想看看它的样子:

What it currently lokks like

1 个答案:

答案 0 :(得分:0)

我认为你可以结合以下两篇文章中给出的答案:

创建位图: How to crop an image in android?

使用画布将位图裁剪为圆形。 Android - Cut a circle from a square Bitmap

亲切的问候