Cannot Convert Listview to Bitmap - android

I am trying to convert layout to bitmap. The layout contains Textview and Listview. Textview is displaying in Bitmap but Listview is displaying but not displaying(showing empty) in drawing cache. Here is my code
Print.xml
<LinearLayout
android:id="#+id/screen_print1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/tax_amnt"
android:layout_width="360dp"
android:layout_height="wrap_content"
android:gravity="right"
android:text="Tax : $200" />
<ListView
android:id="#+id/item_listview1"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:layout_gravity="center" />
</LinearLayout>
Print.java
LinearLayout screenshot = (LinearLayout) findViewById(R.id.screen_print1);
ListView items_display=(ListView)findViewById(R.id.item_listview1);
TextView tax_amount=(TextView)findViewById(R.id.tax_amnt);
tax_amount.setText("$5000");
ArrayList<HashMap<String, String>> bill_list1=OrderSummaryFragment.item_lists;
itl1 = new Itemlist(getApplicationContext(), bill_list1);
items_display.setAdapter(itl1);
screenshot.setDrawingCacheEnabled(true);
screenshot.buildDrawingCache();
Bitmap bm = screenshot.getDrawingCache();
screen_imageview.setImageBitmap(bm);

Update the lines
screenshot.setDrawingCacheEnabled(true);
screenshot.buildDrawingCache();
to
screenshot.setDrawingCacheEnabled(true);
screenshot.measure(View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED),View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
screenshot.layout(0, 0, screenshot.getMeasuredWidth(), screenshot.getMeasuredHeight());
screenshot.buildDrawingCache(true);

Related

How to add a button over an ImageView in ScrollView dynamically? Android. Xamarin

I have an axml file:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mylinearlayout"
android:orientation="vertical"
android:configChanges="orientation|keyboardHidden"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<SurfaceView
android:id="#+id/surfaceView"
android:layout_height="1dip"
android:layout_width="1dip" />
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/scrollView1">
<LinearLayout
android:id="#+id/filesScrollerLayout"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</ScrollView>
<VideoView
android:layout_width="1dip"
android:layout_height="1dip"
android:id="#+id/videoView1" />
My application takes a photo and video and puts it in the LinearLayout.
When I add video, I create an ImageView dynamically, put the firstframe of the video in this ImageView and add it in LinearLayout.
private void addBitmapToLayout(Bitmap bitmap)
{
ImageView iv = new ImageView(this);
iv.SetImageBitmap(bitmap);
linearlayout.AddView(iv);
}
How can I put a button over this ImageView in LinearLayuot dynamically to start the video?
Like this
Thank you.
Instead of adding an ImageView to your LinearLayout, add a custom layout where you'll have your ImageView as well as a Button on top
Define the layout for each item in your list :
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="#+id/button"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</RelativeLayout>
Your function now becomes :
private void addBitmapToLayout(Bitmap bitmap) {
LayoutInflater inflater = LayoutInflater.from(context);
RelativeLayout layout = inflater.inflate(R.layout.list_item, null, false);
ImageView iv = (ImageView) layout.findViewById(R.id.imageView);
iv.SetImageBitmap(bitmap);
//Add click listener to your Button etc...
Button button = (Button) layout.findViewById(R.id.button);
linearlayout.AddView(layout);
}

android customize tablerow with imageview overflow tablerow

i am trying to create a tablelayout to show one user's profile picture and his name.Everything works fine except the layout is wired. the image view overflow the tablerow. i set the tablerow layout_height="70dp" and iamgeview layout_height ="50dp" and layout_margin="10dp" in order to vertically centrallize the image.
tablerow xml:
<?xml version="1.0" encoding="utf-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="70dp"
android:orientation="horizontal"
android:layout_marginBottom="1dp"
android:background="#fff">
<ImageView
android:layout_height="50dp"
android:layout_width="50dp"
android:id="#+id/pic"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:background="#f00"/>
<TextView
android:layout_height="20dp"
android:layout_width="wrap_content"
android:layout_marginTop="25dp"
android:layout_marginRight="25dp"
android:id="#+id/value"
android:textColor="#000"
android:layout_alignParentRight="true"
android:layout_weight="3.0"
android:textAlignment="gravity"
android:gravity="right"
/>
</TableRow>
tablelayout xml:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#fff">
<TableLayout android:id="#+id/contact_table"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#aaa">
</TableLayout>
</ScrollView>
java code:
table =(TableLayout)findViewById(R.id.contact_table);
LayoutInflater inflater = getLayoutInflater();
TableRow row = (TableRow)inflater.inflate(R.layout.profilerow, table, false);
ImageView tag = (ImageView)row.findViewById(R.id.pic);
new DownloadImageTask(tag).execute(me.getDp_address());
TextView value = (TextView)row.findViewById(R.id.value);
value.setText(me.getFirst_name()+" "+me.getLast_name());
table.addView(row);
TableRow row2 = (TableRow)inflater.inflate(R.layout.centertextrow,table ,false);
table.addView(row2);
private class DownloadImageTask extends AsyncTask<String,Void,Bitmap>{
ImageView img;
public DownloadImageTask(ImageView bmImage){
this.img = bmImage;
}
#Override
protected Bitmap doInBackground(String... urls) {
String url_string = urls[0];
Bitmap micoin = null;
try {
InputStream in = new java.net.URL(url_string).openStream();
micoin = BitmapFactory.decodeStream(in);
} catch (IOException e) {
Log.i("michaellog","error a");
//Log.e("michaellog",e.getMessage());
e.printStackTrace();
}
return micoin;
}
#Override
protected void onPostExecute(Bitmap bitmap) {
super.onPostExecute(bitmap);
img.setImageBitmap(bitmap);
}
}
here is an image of how it looks like:link
the image shift down.
Aloha!
I ran into the same type of problem when creating a list of youtube feeds that was put into a table view for our university app. The only difference I see from my layout and yours is I have added a android:scaleType="centerCrop" to the tableview cell that is created. This should scale your image to fit in the correct area. I am also using a linear layout instead of the tableRow type for each cell in the table that gets populated. I would also check out the answer here as well. https://stackoverflow.com/a/15832564/877568
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="#+id/semesterButtonLL"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView android:layout_width="50dip"
android:id="#+id/image"
android:src="#drawable/icon72"
android:layout_height="50dip"
android:scaleType="centerCrop">
</ImageView>
<TextView android:text="TextView"
android:id="#+id/text"
android:textColor="#color/usu_blue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical"
android:textSize="20dip"
android:layout_marginLeft="10dip">
</TextView>
</LinearLayout>
As for the code you provided everything looks ok on how you are bringing the data in and if it is displaying the image on the link you provided then it may be as simple as adding the centerCrop to the line in your xml. I hope this helps.

How to use Image Mask with ListView

I have an activity that list data with listView with their row's images.
String[] from = {"subject","img","description","id"};
int[] to = {R.id.tv_subject,R.id.iv_pic, R.id.tv_details, R.id.hide_id};
SimpleAdapter adapter = new SimpleAdapter(ListViewActivity.this,searchResult,R.layout.listview, from, to);
mListView.setAdapter(adapter);
My ListView.xml is :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:background="#ffffff"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="#+id/iv_pic"
android:layout_gravity="left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"/>
<TextView
android:textColor="#000000"
android:layout_gravity="center"
android:id="#+id/tv_subject"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<TextView
android:textColor="#000000"
android:layout_gravity="right"
android:paddingRight="5dp"
android:id="#+id/tv_details"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:visibility="gone"
android:id="#+id/hide_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
now I have a part of code that display image with mask:
ImageView mImageView= (ImageView)findViewById(R.id.img);
ImageView mImageView1= (ImageView)findViewById(R.id.img1);
Bitmap original = BitmapFactory.decodeResource(getResources(),R.drawable.c);
Bitmap mask = BitmapFactory.decodeResource(getResources(),R.drawable.poster);
Bitmap result = Bitmap.createBitmap(mask.getWidth(), mask.getHeight(), Config.ARGB_8888);
Canvas mCanvas = new Canvas(result);
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setXfermode( new PorterDuffXfermode(Mode.DST_IN));
mCanvas.drawBitmap(original, 0, 0, null);
mCanvas.drawBitmap(mask, 0, 0, paint);
paint.setXfermode(null);
mImageView.setImageBitmap(result);
I wish to display each image in listview with mask(each image is in a row if listview)
In order to customize the inflation of your ListView (eg. set "masks") you have to subclass the SimpleAdapter you have created and override the getView(int position, View convertView, ViewGroup parent) method.
In that method you check the view that was clicked and inflate it appropriately, setting the ImageView's and TextViews that you desire. And also within that method you will fill in the data that corresponds to the view that is being inflated.
Check out this tutorial for more.

TextView android:gravity set to center_horizontal not working correctly when drawn to a bitmap

IMPORTANT:
I want to draw content of a View A to a bitmap and part of the View A is a TextView which text has to be centered horizontally. The View A is not displayed nor is part of another View.
QUESTION:
How can I tell the TextView to display the text correctly when it is drawn to a bitmap????
My base layout(base_layout.xml):
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:baselineAligned="false" >
<TextView
android:id="#+id/dateTV"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginRight="5dp"
android:gravity="center"
android:padding="3dp"
android:textStyle="bold" />
<TextView
android:id="#+id/shiftsListTV"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:singleLine="false"
android:maxLines="2"
android:padding="3dp" />
</LinearLayout>
My TestActivity.java activity, which I use for testing:
public class TestActivity extends Activity {
private LinearLayout mainHolderLL;
#Override
protected int getLayoutXml() {
return R.layout.activity_test;
}
#Override
protected final void onCreate(Bundle savedInstanceState) {
mainHolderLL = (LinearLayout) findViewById(R.id.mainHolderLL);
View baseLayoutView = View.inflate(context, R.layout.base_layout, null);
dateTV.setText("Feb 2014");
shiftsListTV.setText("shift1, shift2");
int width = 500;
int height = 500;
int widthMeasureSpec = MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY);
int heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY);
baseLayoutView.measure(widthMeasureSpec, heightMeasureSpec);
baseLayoutView.layout(0, 0, baseLayoutView.getMeasuredWidth(), baseLayoutView.getMeasuredHeight());
Bitmap bitmap = Bitmap.createBitmap(baseLayoutView.getMeasuredWidth(), baseLayoutView.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
baseLayoutView.draw(canvas);
ImageView appwidget_image_view = (ImageView) findViewById(R.id.appwidget_image_view);
appwidget_image_view.setImageBitmap(bitmap);
}
}
activity_test.xml:
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="#+id/mainHolderLL"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="#dimen/common_padding_normal" >
<ImageView
android:id="#+id/appwidget_image_view"
android:layout_width="294dp"
android:layout_height="294dp"
android:background="#android:color/black"
android:cropToPadding="false"
android:padding="#dimen/widget_margin"
android:scaleType="fitXY"
tools:ignore="ContentDescription" />
</LinearLayout>
</ScrollView>
</HorizontalScrollView>
If the bitmap is displayed inside a ImageView, the text inside dateTV TextView is not centered horizontally and it looks as crushed(on Android 4.3 but on Android 2.3.3 nothing is displayed), but the text inside shiftsListTV is displayed correctly.
If I remove the android:gravity attribute from dateTv TextView the text inside dateTV is displayed correctly but is not centered. I need the text centered.
Edit:
After some research I found out that TextView has a problem with gravity tag.
The imageview is NOT important it is solely for displaying the bitmap.

Taking a "screenshot" of a specific layout in Android

I have two main issues which are closely linked. I am looking at these problems from a programmatic point of view.
(1) - I wish to take a screenshot of the contents of a SPECIFIC layout, i.e. a ScrollView nested in a LinearLayout.
(2) - As the ScrollView has content that spills out of the screen (hence scrolling made possible), how can I ensure that the screenshot includes the elements that are not visible on the screen?
This is the current block of code I use. It does the job of taking a screenshot but only for the entire screen. This is even though R.id.boss is the ID of the ScrollView and not the main LinearLayout.
View view = findViewById(R.id.boss);
View v = view.getRootView();// this does not seem to make a difference
v.setDrawingCacheEnabled(true);
v.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
v.buildDrawingCache(true);
Bitmap b = Bitmap.createBitmap(u.getDrawingCache());
v.setDrawingCacheEnabled(false);
Thanks in advance.
EDIT:
I've made a few mistakes. I used R.id.boss which is the wrong resource. I am now able to take a screenshot of the scrollview alone, less the out-of-screen parts.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/boss"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="top"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="F"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Analyze via image URL"
android:textAppearance="?android:attr/textAppearanceSmall" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<EditText
android:id="#+id/mUrl"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.7"
android:text="http://" >
<requestFocus />
</EditText>
<ImageView
android:id="#+id/call"
android:layout_width="75dp"
android:layout_height="50dp"
android:layout_weight="0.3"
android:text="ABC"
android:src="#drawable/run" />
</LinearLayout>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="ABC"
android:textAppearance="?android:attr/textAppearanceSmall" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/filepath"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.55" />
<ImageView
android:id="#+id/cam"
android:layout_width="75dp"
android:layout_height="50dp"
android:layout_weight="0.15"
android:src="#drawable/cam" />
<ImageView
android:id="#+id/browse"
android:layout_width="75dp"
android:layout_height="50dp"
android:layout_weight="0.15"
android:src="#drawable/folder"
android:text="B" />
<ImageView
android:id="#+id/upload"
android:layout_width="75dp"
android:layout_height="50dp"
android:layout_weight="0.15"
android:src="#drawable/run"
android:text="A" />
</LinearLayout>
<LinearLayout
android:id="#+id/baba"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ScrollView
android:id="#+id/scroll"
android:layout_width="fill_parent"
android:layout_height="150dp"
android:layout_weight="0.7" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="186dp"
android:orientation="vertical" >
<ImageView
android:id="#+id/pic"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Facial recognition"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/text3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/avmarwe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Gender and age"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/skahasd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Expression and mood"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/dsfsfs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Celebrity Facial Match"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/text4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
</ScrollView>
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom" >
<Button
android:id="#+id/c"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_weight="0.7"
android:text="" />
<Button
android:id="#+id/share"
android:layout_width="70dp"
android:layout_height="50dp"
android:layout_weight="0.3"
android:text="" />
</LinearLayout>
</LinearLayout>
Thanks to you guys, I've finally found out what was wrong.
View v = view.getRootView(); should not be used because it will call the root view which I do not want. I mistakenly thought this did not make a difference because I had entered the wrong resource ID.
MeasureSpec somehow did not give a good account of the width and height. So I ended up using another method:
...
ScrollView z = (ScrollView) findViewById(R.id.scroll);
int totalHeight = z.getChildAt(0).getHeight();
int totalWidth = z.getChildAt(0).getWidth();
u.layout(0, 0, totalWidth, totalHeight);
...
As ScrollView's total height can be determined by the single child element that it has.
After making these changes, I am now able to take a screenshot of a nested ScrollView and all its contents, visible or not. For anyone interested, here is the block of code including the saving of the bitmap:
View u = findViewById(R.id.scroll);
u.setDrawingCacheEnabled(true);
ScrollView z = (ScrollView) findViewById(R.id.scroll);
int totalHeight = z.getChildAt(0).getHeight();
int totalWidth = z.getChildAt(0).getWidth();
u.layout(0, 0, totalWidth, totalHeight);
u.buildDrawingCache(true);
Bitmap b = Bitmap.createBitmap(u.getDrawingCache());
u.setDrawingCacheEnabled(false);
//Save bitmap
String extr = Environment.getExternalStorageDirectory().toString() + File.separator + "Folder";
String fileName = new SimpleDateFormat("yyyyMMddhhmm'_report.jpg'").format(new Date());
File myPath = new File(extr, fileName);
FileOutputStream fos = null;
try {
fos = new FileOutputStream(myPath);
b.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();
MediaStore.Images.Media.insertImage(getContentResolver(), b, "Screen", "screen");
}catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try this it works fine for me
TableLayout tabLayout = (TableLayout) findViewById(R.id.allview);
if (tabLayout != null) {
Bitmap image = Bitmap.createBitmap(tabLayout.getWidth(),
tabLayout.getHeight(), Config.ARGB_8888);
Canvas b = new Canvas(image);
tabLayout.draw(b);
}
EDIT : after seeing OP's comment
You dont need to think about new activities at all.. Say you are in Activity right now.. Layout A is the main layout for the activity, Layout B and C are two child layouts inside Layout A. Like this,
Layout A -> Parent
|
-------Layout B
|
-------Layout C
Now if you want to take screenshot of C only
1) in onCreate() of activity
LinearLayout myCLayout = (LinearLayout)this.findViewbyId(R.id.my_c_layout);
ViewTreeObserver vto = myCLayout.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
//fully drawn, no need of listener anymore
myCLayout.getViewTreeObserver().removeGlobalOnLayoutListener(this);
getDrawingBitmap();
}
});
where getDrawingBitmap() is a function..to take your screenshot..
public void getDrawingBitmap(){
LinearLayout myCLayout = (LinearLayout)this.findViewbyId(R.id.my_c_layout);
Bitmap b = myCLayout.getDrawingCache();
File file = saveBitmapAsFile(b);
}
EDIT: For ScrollView
I never tried it.. But I think you can do this..
1) first override scrollView, and override onMeasure function..
public class MyScrollView extends ScrollView{
public MyScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
}
#Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){
super.onMeasure(widthMeasureSpec, yourFullScrollViewHeight));
}
}
and use MyScrollView in your layout.. here yourFullScrollViewHeight is the height of all scrollView content you need to take screenshot of.. I never tried this.. But it might work..
Here is the exact solution you want, It will display entire screen including content hidden in your ScrollView
LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
FrameLayout root = (FrameLayout) inflater.inflate(R.layout.activity_main, null); // activity_main is UI(xml) file we used in our Activity class. FrameLayout is root view of my UI(xml) file.
root.setDrawingCacheEnabled(true);
Bitmap bitmap = getBitmapFromView(this.getWindow().findViewById(R.id.frameLayout)); // here give id of our root layout (here its my FrameLayout's id)
Display bitmap in your ImageView or use it as you want. Enjoy..
I also had this problem and coded it myself.
I used this code to take screenshot of whole layout.
I did modified the list size and some mathematical items.
See the following website,
Try this code
public Bitmap screenShot(View view)
{
Bitmap bitmap = Bitmap.createBitmap(view.getWidth(),
view.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
view.draw(canvas);
return bitmap;
}

Categories

Resources