How to get the drawable from relative layout in android

眉间皱痕 提交于 2019-12-02 13:25:26

There are a couple of ways you can do this:

1. Try:

RelativeLayout layout = (RelativeLayout)findViewById(R.id.rel);
layout.setDrawingCacheEnabled(true);
bitmap = Bitmap.createBitmap(layout.getDrawingCache());
layout.setDrawingCacheEnabled(false);

2. Or try:

RelativeLayout layout = (RelativeLayout)findViewById(R.id.rel);
Bitmap b = Bitmap.createBitmap( layout.getLayoutParams().width, layout.getLayoutParams().height, Bitmap.Config.ARGB_8888);                
Canvas c = new Canvas(b);
layout.layout(layout.getLeft(), layout.getTop(), layout.getRight(), layout.getBottom());
layout.draw(c);

To get the current ImageView

1. To get current position, use

ViewPager viewPager = getView().findViewById(r.id.pager);
int position = viewPager.getCurrentItem();

2. To get the current View, use

View currentView = viewPager.getChildAt(int position);

This currentView is the View created by the onCreateView() method of the current Fragment.

3. To get the ImageView, use

ImageView currentImage = (ImageView)currentView.findViewById(R.id.image);

where R.id.image is the ImageView object you want from the current Fragment.

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