LayerDrawable.setLayerInset() not working on android 2.3

不问归期 提交于 2019-12-23 19:19:08

问题


Following sample working for android 4.1 but for android 2.3 left and right inset are not changed. What is the reason for this behavior?

public class MyFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.badges_fragment_layout, container, false);

    view.setBackgroundDrawable(getCustomDrawable());
    return view;
} 

private Drawable getCustomDrawable() {
    LayerDrawable layerDrawable = new LayerDrawable(new Drawable[]{getBottom(),     getTop()});
    layerDrawable.setLayerInset(1, 5, 0, 5, 0);
    return layerDrawable.mutate();
}

private Drawable getTop() {
    return new ColorDrawable(Color.parseColor("#ffffff"));
}

private Drawable getBottom() {
    return new ColorDrawable(Color.parseColor("#ff0000));
}

来源:https://stackoverflow.com/questions/16826075/layerdrawable-setlayerinset-not-working-on-android-2-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!