Show Button over a bitmap not imageview - android

I have a full screen activity that is used to show the advertisement. Advertisement is just a image and there is a cross button over the image. Everything seems to work fine the only issue I am facing is when the image coming from server is in landscape mode then cross button remains at top and image at center
When image is in portrait mode then image comes in full screen and cross at the top
Can anyone suggest me how to move cross button over the image loaded like in second image for landscape images.
Here is my code
img = (ImageView) findViewById(R.id.adimage);
try {
obj = new JSONObject(store.getString(Constants.PROFILE_STRING));
JSONObject advert = obj.getJSONObject("advertisement");
url = advert.getString("url");
image = advert.getString("image");
name = advert.getString("name");
DisplayImageOptions options = new DisplayImageOptions.Builder()
.imageScaleType(ImageScaleType.EXACTLY)
.cacheOnDisc(true)
.build();
il.loadImage(image, options, new ImageLoadingListener() {
#Override
public void onLoadingStarted(String imageUri, View view) {
}
#Override
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
}
#Override
public void onLoadingCancelled(String imageUri, View view) {
}
#Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
img.setImageBitmap(loadedImage);
findViewById(R.id.close).setVisibility(View.VISIBLE);
}
});
} catch (JSONException e) {
e.printStackTrace();
}
Here is my layout file
<RelativeLayout 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"
android:fitsSystemWindows="true"
android:padding="10dp"
tools:context="soulvant.golfclub.Advertisement">
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true">
<!--<ImageView
android:id="#+id/backgroundImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>-->
<ImageView
android:id="#+id/adimage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
<ImageView
android:id="#+id/close"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentTop="true"
android:layout_alignRight="#+id/adimage"
android:layout_alignTop="#+id/adimage"
android:layout_gravity="right|top"
android:padding="5dp"
android:scaleType="centerCrop"
android:src="#drawable/a_close_button"
android:visibility="gone" />
</FrameLayout>

Well, you can do it this way.
Get the width and height of the adImage when it's downloaded
Then, place the close button/image on the adImage, specifying the location where you want to place the image

Try by keep android:adjustViewBounds="true" in your imageview this property adjust image bounds to preserve the aspect ratio of its drawable.do like:
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" >
<ImageView
android:id="#+id/adimage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true" />
<ImageView
android:id="#+id/close"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="right|top"
android:padding="5dp"
android:scaleType="centerCrop"
android:src="#drawable/ic_launcher"
android:visibility="gone" />
</FrameLayout>

Related

How to load multiple images on the same imageview by clicking a button?

Basically, I want to have an AlertDialog in which multiple images will load on the same ImageView. By clicking the NEXT button it will get the next image bitmap from bitmap list and finally will load on that ImageView. Same case for PREV button. It will take previous bitmap and will load the image on the same ImageView.
But the problem is after loading the first image it does not load the next image. If I click the next button then it takes the next bitmap but the imageview.setImageBitmap(bitmap) does not work.
How to remove or clear the previous image to place the next photos?
The XML file are given below :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#color/white">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/question"
android:gravity="center"
android:layout_marginTop="15dp"
android:layout_marginBottom="15dp"
android:text="#string/question"
android:textSize="14sp"
android:textColor="#color/light_black"/>
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="#color/divider"/>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="0dp"
app:cardElevation="0dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="300dp"
android:id="#+id/selected_place_images"
android:scaleType="centerCrop"/>
</LinearLayout>
</android.support.v7.widget.CardView>
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="#color/divider"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="47dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/previous"
android:text="#string/previous_page"
android:textColor="#color/black"
android:layout_centerVertical="true"
android:layout_marginStart="10dp"
android:layout_alignParentStart="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/next"
android:text="#string/next_page"
android:textColor="#color/black"
android:layout_centerVertical="true"
android:layout_marginEnd="10dp"
android:layout_alignParentEnd="true"/>
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
The java code are given below :
private void showDialogOfImages() {
Log.d(TAG,"showDialogOfImages : showing places images");
AlertDialog.Builder builder = new AlertDialog.Builder(context);
LayoutInflater inflater = this.getLayoutInflater();
View customLayout = inflater.inflate(R.layout.custom_displaying_selected_place_images,null);
mSelectedPlaceImages = (ImageView) customLayout.findViewById(R.id.selected_place_images);
nextPage = (TextView) customLayout.findViewById(R.id.next);
previousPage = (TextView) customLayout.findViewById(R.id.previous);
displayPhoto();
nextPage.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mCurrentPhotoIndex++;
displayPhoto();
}
});
previousPage.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mCurrentPhotoIndex--;
displayPhoto();
}
});
builder.setView(customLayout);
builder.show();
}
private void displayPhoto() {
if (mCurrentPhotoIndex < mSelectedLocationPhotosBitmap.size()) {
Bitmap bitmap = mSelectedLocationPhotosBitmap.get(mCurrentPhotoIndex);
Toast.makeText(context,""+mCurrentPhotoIndex+" : "+bitmap,Toast.LENGTH_LONG).show();
mSelectedPlaceImages.setImageBitmap(bitmap);
setButtonVisibility();
}
}
private void setButtonVisibility() {
if(mCurrentPhotoIndex == 0 && mSelectedLocationPhotosBitmap.size() == 1){
nextPage.setEnabled(false);
nextPage.setClickable(false);
nextPage.setTextColor(getResources().getColor(R.color.divider));
previousPage.setEnabled(false);
previousPage.setClickable(false);
previousPage.setTextColor(getResources().getColor(R.color.divider));
}
else if (mCurrentPhotoIndex == 0 && mSelectedLocationPhotosBitmap.size() > 1){
nextPage.setEnabled(true);
nextPage.setClickable(true);
nextPage.setTextColor(getResources().getColor(R.color.black));
previousPage.setEnabled(false);
previousPage.setClickable(false);
previousPage.setTextColor(getResources().getColor(R.color.divider));
}
else if (mCurrentPhotoIndex == mSelectedLocationPhotosBitmap.size()-1 && mSelectedLocationPhotosBitmap.size() > 1){
nextPage.setEnabled(false);
nextPage.setClickable(false);
nextPage.setTextColor(getResources().getColor(R.color.divider));
previousPage.setEnabled(true);
previousPage.setClickable(true);
previousPage.setTextColor(getResources().getColor(R.color.black));
}
else{
nextPage.setEnabled(true);
nextPage.setClickable(true);
nextPage.setTextColor(getResources().getColor(R.color.black));
previousPage.setEnabled(true);
previousPage.setClickable(true);
previousPage.setTextColor(getResources().getColor(R.color.black));
}
}
You need to clear the previous image from imageview and then you can set the new on top.
Do as below
private void displayPhoto() {
if (mCurrentPhotoIndex < mSelectedLocationPhotosBitmap.size()) {
Bitmap bitmap = mSelectedLocationPhotosBitmap.get(mCurrentPhotoIndex);
Toast.makeText(context,""+mCurrentPhotoIndex+" : "+bitmap,Toast.LENGTH_LONG).show();
mSelectedPlaceImages.setImageBitmap(null)
mSelectedPlaceImages.setImageBitmap(bitmap);
setButtonVisibility();
}
}
Try this:
mSelectedPlaceImages.destroyDrawingCache();
mSelectedPlaceImages.setImageBitmap(bitmap);
mSelectedPlaceImages.buildDrawingCache();

universal image loader not working for Relative layout in ArrayAdapter

i have list of image path's in json response. i prompt to set the images as background of relative layout from the path. so on this i have been advised and used to ArrayAdapter and universal image loader to achieve this.i hope myself 95% i have done this. but the problem is its loaded only one image in my ui which is from two images where i have in json response.
here i tried in ArrayAdapter class inside getView() method
RelativeLayout layContentOfListView;
// Initialize the Relative layout container
layContentOfListView = (RelativeLayout)rowView.findViewById(R.id.layContentOfListView);
// Load image, decode it to Bitmap and return Bitmap to callback
ImageSize targetSize = new ImageSize(150, 100); // result Bitmap will be fit to this size
imageLoader.loadImage(fullImagePath, targetSize, new SimpleImageLoadingListener() {
#Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
if (loadedImage != null) {
Drawable d = new BitmapDrawable(context.getResources(), loadedImage);
layContentOfListView.setBackgroundDrawable(d);
}
}
});
this is my relative layout content in the list view of each row.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/layContentOfListView"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingBottom="10dp"
android:orientation="vertical"
android:background="#drawable/gray_boardered_transparent_shape"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/color_red"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:id="#+id/layHeader"
android:layout_marginBottom="10dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/lblMerchantName"
android:layout_weight="1"
android:text="Merchant Name"
android:textAlignment="textStart"
android:textSize="15sp"
android:textColor="#color/color_white"
/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:id="#+id/lblRewardPoints"
android:text="Reward points"
android:textSize="15sp"
android:textColor="#color/color_white"
android:gravity="center"
android:layout_centerHorizontal="true"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:id="#+id/lblRewardName"
android:text="Reward Name"
android:textSize="15sp"
android:textColor="#color/color_white"
android:layout_below="#+id/lblRewardPoints"
android:layout_centerHorizontal="true"
/>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:id="#+id/imgMemStar"
android:src="#drawable/icon_mem_star"
android:layout_below="#+id/lblRewardName"/>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginRight="40dp"
android:id="#+id/imgMemHand"
android:src="#drawable/icon_mem_like"
android:layout_below="#+id/lblRewardName"
android:layout_toLeftOf="#+id/imgMemPhone"
/>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:id="#+id/imgMemPhone"
android:src="#drawable/icon_mem_phone"
android:layout_below="#+id/lblRewardName"
android:layout_centerHorizontal="true"/>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginLeft="40dp"
android:id="#+id/imgMemQRCode"
android:src="#drawable/icon_mem_qr"
android:layout_below="#+id/lblRewardName"
android:layout_toRightOf="#+id/imgMemPhone"
/>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:id="#+id/imgMemLocation"
android:src="#drawable/icon_mem_location"
android:layout_below="#+id/lblRewardName"
android:layout_alignParentRight="true"/>
</RelativeLayout>
and this is my output screen
i can't found the solution as too long. can anyone please charity on this.Thanks.!
I have tested this and it is working fine.
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.RelativeLayout;
import com.squareup.picasso.Picasso;
import com.squareup.picasso.Target;
public class MainActivity extends AppCompatActivity {
RelativeLayout relativeLayout;
String url = "Image_URL";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
relativeLayout = (RelativeLayout) findViewById(R.id.lay);
Picasso.with(this)
.load(url)
.into(new Target() {
#Override
public void onBitmapLoaded (final Bitmap bitmap, Picasso.LoadedFrom from){
/* Save the bitmap or do something with it here */
//Set it in the ImageView
Drawable dr = new BitmapDrawable(bitmap);
relativeLayout.setBackground(dr);
}
#Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
}
#Override
public void onBitmapFailed(Drawable errorDrawable) {
}
});
}
}
Use this in manifest before Application.
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
Add the following line in dependencies or Gradle.
compile 'com.squareup.picasso:picasso:2.5.2'
You should use the picasso library, it is the best.
Add the following line in dependencies or Gradle.
compile 'com.squareup.picasso:picasso:2.5.2'
And use the following code to load the image in ImageView.
Picasso.with(this)
.load(pictureURL)
.into(ImageView);
So Simple. For more details check these links. 1, 2
I think it will load on an image view create a fakeimageview and supply it to the uil and then inloading complete you have the bitmap set it on your relative layout

ImageView is small after rotation of device

After rotation of device -> Image (id=list_image2) remains small like it was at portrate mode
Seems it is because I change count of Columns gridView.setNumColumns(3);, but viewholder still contains previous imageview with previous width and height, also I tryed to make gridView.invalidate(); in onConfigurationChanged...but no result
added to activity in Manifest
android:configChanges="keyboardHidden|orientation|screenSize"
Here is item_grid.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/list_row_root"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:paddingLeft="1dip"
android:paddingRight="1dip"
<ImageView
android:id="#+id/list_image2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:minWidth="#dimen/grid_item_width"
android:minHeight="#dimen/grid_item_height"
android:src="#drawable/ic_action_cloud"
android:scaleType="fitXY"
/>
<ProgressBar
android:id="#+id/progressBar1"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="30dp"
android:layout_alignBottom="#+id/list_image2"
android:layout_alignTop="#+id/list_image2"
android:layout_centerHorizontal="true" />
<RelativeLayout
android:id="#+id/likes_RelativeLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/field_likes"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:layout_alignBottom="#+id/list_image2"
android:layout_alignRight="#+id/list_image2"
android:layout_marginRight="4dp"
android:layout_marginBottom="4dp" >
<TextView
android:id="#+id/likes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:textColor="#android:color/white"
android:text="265465" />
<ImageView
android:id="#+id/btn_favoutites"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:layout_toRightOf="#+id/likes"
android:src="#drawable/btn_rating_star_on_normal_holo_dark"
android:text="Button" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/btn_RelativeLayout"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignBottom="#+id/likes_RelativeLayout"
android:layout_alignLeft="#+id/likes_RelativeLayout"
android:layout_alignRight="#+id/likes_RelativeLayout"
android:layout_alignTop="#+id/likes_RelativeLayout"
android:background="#drawable/field_like_clickable_style" >
</RelativeLayout>
Here is my adapter:
publ
ic class LazyAdapter2 extends BaseAdapter{
public LazyAdapter2(Context context, ArrayList<WallImage> d) {
mContext = context;
data=d;
inflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
imageLoader = ImageLoader.getInstance();
options = new DisplayImageOptions.Builder()
.cacheInMemory(true)
.cacheOnDisk(true)
.resetViewBeforeLoading(true)
.imageScaleType(ImageScaleType.EXACTLY)// default
.build();
}
public View getView( int position, View convertView, ViewGroup parent) {
final ViewHolderItem viewHolder;
if(convertView==null)
{
convertView = inflater.inflate(R.layout.item_grid, null);
viewHolder = new ViewHolderItem();
viewHolder.thumb_image=(ImageView)convertView.findViewById(R.id.list_image2); // thumb image
convertView.setTag(viewHolder);
}else{
viewHolder = (ViewHolderItem) convertView.getTag();
}
WallImage imageObject = data.get(position);
viewHolder.likes.setText(imageObject.views);
imageLoader.displayImage(imageObject.preview, viewHolder.thumb_image, options);
return convertView;
}
}
Not just invalidate but how about like this with Handler.post()?:
new Handler(getMainLooper()).post(new Runnable() {
#Override
public void run() {
gridView.invalidate();
}
});
Maybe this is due to the use of convertView in your getView method?
It keeps the original layout and don't recreate it when orientation change.
You could add to your ViewHolderItem class a boolean member that indicates the screen orientation.
And when you recycle the view, you test your viewHolder orientation. If it's different from the current screen orientation, don't recycle it.
Solved by changing of item_grid.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/list_row_root"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:paddingLeft="1dip"
android:paddingRight="1dip"
>
<ImageView
android:id="#+id/list_image2"
android:layout_width="match_parent"
android:layout_height="#dimen/grid_item_height"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:scaleType="centerCrop"
android:src="#android:color/transparent"
/>
after doing of ImageView android:layout_height="#dimen/grid_item_height" => after rotation of screen image size remains constant, but to resize imege in ImageView I use android:scaleType="centerCrop" after that image is slighly cutted , but problem is solved
Try imageScaleType(ImageScaleType.IN_SAMPLE_INT)
and
imageLoader.displayImage(imageObject.preview, viewHolder.thumb_image, options);
viewHolder.thumb_image.setScaleType(ImageView.ScaleType.FILL_XY);

Imageview relative layout - changes position on picture taken

I have an imageview whose image(here) is loaded from a asset file onCreateInstance() and the same imageview is rotated and loaded with the images taken from a camerahere (using camera API on picture taken). The imageview changes position when rotated and moves around every time i take a new picture.
Here is the relative layout structure:
<RelativeLayout
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"
tools:context=".MainPage" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="16dip"
android:onClick="uploadFile"
android:text="Upload" />
<TextView
android:id="#+id/ins"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="26dp"
android:text="Please scan the QR code on the package to retrieve the package ID"
android:textAppearance="?android:attr/textAppearanceSmall" />
<Button
android:id="#+id/scan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/ins"
android:layout_centerHorizontal="true"
android:layout_marginTop="21dp"
android:onClick="scan"
android:text="Scan" />
<Button
android:id="#+id/captureFront"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/button1"
android:layout_centerHorizontal="true"
android:layout_marginBottom="26dp"
android:onClick="onClick"
android:text="Camera" />
<ImageView
android:id="#+id/result"
android:layout_width="200dip"
android:layout_height="150dip"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:contentDescription="#string/imageView"
android:scaleType="fitXY"
android:src="#drawable/ic_launcher" />
</RelativeLayout>
The following code shows how the imageview is loaded with images (programatically)
imageView.setImageBitmap(loadDataFromAsset());
public Bitmap loadDataFromAsset() {
InputStream in = null;
try {
in = getAssets().open("signBG.jpeg");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Bitmap bmp = BitmapFactory.decodeStream(in);
return bmp;
}
The above code is called via OnCreateInstance() and
The following code updates the imageview onResume
#Override
public void onResume() {
super.onResume();
setImage();
}
and when the activity resumes (OnResume())
private void setImage(){
if(constants.picTaken){
bitmap = loadPicture("sign.jpeg", bitmap) ;
uploadButton = (Button)findViewById(R.id.button1);
uploadButton.setEnabled(true);
insLabel = (TextView)findViewById(R.id.ins);
insLabel.setText("Please upload on confirmation");
if (bitmap != null) {
//Toast.makeText(this, "not null", Toast.LENGTH_SHORT).show();
imageView.setImageBitmap(bitmap);
imageView.setPivotX(imageView.getHeight()/2);
imageView.setPivotY(imageView.getWidth()/2);
imageView.setRotation(90);
}
}
}
Please do refer to the two images i have linked, for references.
Can the images look consistent as seen loading from the asset file?
This is pretty much a shot in the dark since I can't see both images until the link is fixed in the question.
The problem might be with the rotation, which I believe is occurring after the ImageView is positioned in the layout, then rotated 90 degrees around it's center. Here that rotation pivot is the center of the view if it wouldn't have been rotated.
If that is the case, the best suggestion would be to rotate the bitmap that is being use in the view, instead of rotating the view.

Android capture layout in app

I'm trying to capture my app screen, not all of it only the linear layout.
atm I'm using this which I think should work, but IDK y it's not. It captures all the screen of the phone not only the linearlayout which I wants it to
final LinearLayout ll = (LinearLayout) findViewById(R.id.Linear);
View v1 = ll.getRootView();
v1.setDrawingCacheEnabled(true);
Bitmap bm = v1.getDrawingCache();
part of my xml:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="#+id/Linear" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<ImageView
android:layout_width="60dp"
android:layout_height="60dp" />
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="10dp" />
<ImageView
android:layout_width="15dp"
android:layout_height="18dp"
android:layout_marginRight="10dp"
android:src="#drawable/ll" />
<ImageView
android:layout_width="15dp"
android:layout_height="20dp"
android:src="#drawable/lle" />
</LinearLayout>
atm it should capture the linearlayout which contains only 3imageviews and 2 textviews, but it captures all the xml or the screen.
Your problem is that you are asking for the root view, which is "all the xml". Instead, you should be just using your LinearLayout:
final LinearLayout ll = (LinearLayout) findViewById(R.id.Linear);
ll.setDrawingCacheEnabled(true);
Bitmap bm = ll.getDrawingCache();
by using this we can capture layout and save in to sd card.
ok.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
l1.setDrawingCacheEnabled(true);
img_bitmap = Bitmap.createBitmap(l1.getDrawingCache());
l1.setDrawingCacheEnabled(false);
}
});
}

Categories

Resources