have db with _id,hName,lName,detail,images
images stored in assets
images name in db (SQLite)
list layout without images working fine, but with images layout display's on names not images (no error in logcat)
wanted to bind CursorAdpater with `ImageView'
public void bindView(View view, Context context, Cursor cursor) {
TextView hName = view.findViewById(R.id.hName);
hName.setText(cursor.getString(cursor.getColumnIndex("hName")));
TextView lName = view.findViewById(R.id.lName);
lName.setText(cursor.getString(cursor.getColumnIndex("lName")));
ImageView image = view.findViewById(R.id.image);
InputStream is = null;
try {
is = context.getAssets().open("birds/" + cursor.getColumnIndex("images"));
} catch (IOException e) {
e.printStackTrace();
}
Bitmap bitmap = BitmapFactory.decodeStream(is);
image.setImageBitmap(bitmap);
}
XML file:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/image"
android:scaleType="fitCenter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:padding="24dp"
/>
<TextView
android:id="#+id/hName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/image"
android:layout_marginLeft="21dp"
android:layout_marginStart="10dp"
android:layout_toEndOf="#+id/image"
android:layout_toRightOf="#+id/image"
android:text="Name"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/lName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/image"
android:layout_alignLeft="#+id/hName"
android:layout_alignStart="#+id/hName"
android:textSize="16sp"
android:text="About" />
check the image extension is used in database
then try this
try {
is = context.getAssets().open("birds/" + cursor.getColumnIndex("images"));
Drawable d = Drawable.createFromStream(is, null);
image.setImageDrawable(d);
} catch (IOException e) {
e.printStackTrace();
}
Related
I am creating an app whereby I store input from edittext and spinner into internal storage. I have used MODE_APPEND so that information stored is not overridden. However it is stored horizontally despite me changing the XML orientation to vertical. How do I overcome that problem?
Portion of MainActivity:
public void Save (View view){
// add-write text into file
// add-write text into file
try {
FileOutputStream fileout=openFileOutput("mytextfile.txt", MODE_PRIVATE | MODE_APPEND);
OutputStreamWriter outputWriter=new OutputStreamWriter(fileout);
outputWriter.write(edDate.getText().toString());
outputWriter.close();
//display file saved message
Toast.makeText(getBaseContext(), "File saved successfully!",
Toast.LENGTH_SHORT).show();
} catch (Exception e) {
e.printStackTrace();
}
try {
FileOutputStream fileout=openFileOutput("mytextfile2.txt", MODE_PRIVATE | MODE_APPEND);
OutputStreamWriter outputWriter=new OutputStreamWriter(fileout);
outputWriter.write(spinner.getSelectedItem().toString());
outputWriter.close();
} catch (Exception e) {
e.printStackTrace();
}
}
RecordDisplay.xml
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".recordsdisplay"
android:orientation="vertical">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:text="Date:"
android:textColor="#000000"
android:textSize="15sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/textViewDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="11dp"
android:layout_marginStart="11dp"
android:layout_marginTop="16dp"
android:textColor="#000000"
android:textSize="15sp"
android:visibility="visible"
app:layout_constraintStart_toEndOf="#+id/textView"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:text="Results:"
android:textColor="#000000"
android:textSize="15sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView" />
<TextView
android:id="#+id/textViewResults"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="11dp"
android:layout_marginStart="11dp"
android:textColor="#000"
android:textSize="15sp"
android:visibility="visible"
app:layout_constraintBaseline_toBaselineOf="#+id/textView3"
app:layout_constraintStart_toEndOf="#+id/textView3" />
RecordDisplay.java
TextView date,Results;
FileInputStream fileInputStream;
static final int READ_BLOCK_SIZE = 100;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_recordsdisplay);
date = (TextView) findViewById(R.id.textViewDate);
Results = (TextView) findViewById(R.id.textViewResults);
try {
FileInputStream fileIn=openFileInput("mytextfile.txt");
InputStreamReader InputRead= new InputStreamReader(fileIn);
char[] inputBuffer= new char[READ_BLOCK_SIZE];
String s="";
int charRead;
while ((charRead=InputRead.read(inputBuffer))>0) {
// char to string conversion
String readstring=String.copyValueOf(inputBuffer,0,charRead);
s +=readstring;
}
InputRead.close();
date.setText("Date:" +s);
} catch (Exception e) {
e.printStackTrace();
}
try {
FileInputStream fileIn=openFileInput("mytextfile2.txt");
InputStreamReader InputRead= new InputStreamReader(fileIn);
char[] inputBuffer= new char[READ_BLOCK_SIZE];
String b="";
int charRead;
while ((charRead=InputRead.read(inputBuffer))>0) {
// char to string conversion
String readstring=String.copyValueOf(inputBuffer,0,charRead);
b +=readstring;
}
InputRead.close();
Results.setText("Results:" + b);
} catch (Exception e) {
e.printStackTrace();
}
}
}
enter image description here
You can change ConstraintLayout to LinearLayout. This has the limitation that your XML file must define the exact number of rows when you make the app. If the user can add data and as many rows as she wishes, you should use ListView or RecyclerView instead. For other layout options check out https://developer.android.com/guide/topics/ui/declaring-layout.
I want to create a PDF of "full page" of the activity. The view contains a RecyclerView with many items.
I can take a full dimensions of my Recyclerview but the file is drawed only of the current view. This is my code:
public void tela (){ // create a new document
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
{
PdfDocument document = new PdfDocument();
getScreenshotFromRecyclerView(mRecyclerView);
content = mRecyclerView;
content.setBackgroundColor(Color.parseColor("#303030"));
PdfDocument.PageInfo pageInfo = new PdfDocument.PageInfo.Builder(wil,
height, 1).create();
// create a new page from the PageInfo
PdfDocument.Page page = document.startPage(pageInfo);
// repaint the user's text into the page
content.draw(page.getCanvas());
// do final processing of the page
document.finishPage(page);
// saving pdf document to sdcard
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy - HH-mm-ss",Locale.getDefault());
String pdfName = "Revisões_"
+ sdf.format(Calendar.getInstance().getTime()) + ".pdf";
// all created files will be saved at path /sdcard/PDFDemo_AndroidSRC/
File outputFile = new File(Environment.getExternalStorageDirectory().getPath(), pdfName);
try {
outputFile.createNewFile();
OutputStream out = new FileOutputStream(outputFile);
document.writeTo(out);
document.close();
out.close();
Toast.makeText(this,"PDF gerado com sucesso",Toast.LENGTH_SHORT).show();
Log.i("Gerou", "pdf");
} catch (IOException e) {
e.printStackTrace();
}
}
}
// getting the limits
public void getScreenshotFromRecyclerView(RecyclerView view) {
RecyclerView.Adapter adapter = view.getAdapter();
if (adapter != null) {
int size = adapter.getItemCount();
for (int i = 0; i < size; i++) {
RecyclerView.ViewHolder holder = adapter.createViewHolder(view, adapter.getItemViewType(i));
adapter.onBindViewHolder(holder, i);
holder.itemView.measure(View.MeasureSpec.makeMeasureSpec(view.getWidth(), View.MeasureSpec.EXACTLY),
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
holder.itemView.layout(0, 0, holder.itemView.getMeasuredWidth(), holder.itemView.getMeasuredHeight());
height += holder.itemView.getMeasuredHeight();
}
wil=view.getMeasuredWidth();
}
}
The result is this:
Can I create the pdf with the all values of my Recyclerview?
Thanks.
I implemented a helper class to handle image saving to PDF. In the method saveImageToPDF() I pass:
a TabLayout, which is above my recyclerView
the Bitmap of the recyclerView
the Context
to get the recyclerView Bitmap I used this Take a screenshot of RecyclerView in FULL length
public class PDFHelper {
private File mFolder;
private File mFile;
private Context mContext;
public PDFHelper(File folder, Context context) {
this.mContext = context;
this.mFolder = folder;
if(!mFolder.exists())
mFolder.mkdirs();
}
public void saveImageToPDF(View title, Bitmap bitmap, String filename) {
mFile = new File(mFolder, filename + ".pdf");
if (!mFile.exists()) {
int height = title.getHeight() + bitmap.getHeight();
PdfDocument document = new PdfDocument();
PdfDocument.PageInfo pageInfo = new PdfDocument.PageInfo.Builder(bitmap.getWidth(), height, 1).create();
PdfDocument.Page page = document.startPage(pageInfo);
Canvas canvas = page.getCanvas();
title.draw(canvas);
canvas.drawBitmap(bitmap, null, new Rect(0, title.getHeight(), bitmap.getWidth(),bitmap.getHeight()), null);
document.finishPage(page);
try {
mFile.createNewFile();
OutputStream out = new FileOutputStream(mFile);
document.writeTo(out);
document.close();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
I have found a more simpler way to do it. I am not sure if my code is clean or is this the right way to do it. I had a recycler view with variable size. I wanted to print the whole length of the recycler view in pdf. Also I use IText Pdf just for reference.
Things that I did.
Below is the XML file for the single item in the recycler view. Please note that I have given an ID to the card view as I used card view (You can use any that you want as the root, LinearLayout or RelativeLayout etc.)android:id="#+id/preview_order_list_card_root"
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/preview_order_list_card_root"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center_horizontal"
android:src="#drawable/car"/>
<TextView
android:layout_width="1dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#android:color/darker_gray"
android:text="12"/>
<TextView
android:id="#+id/preview_car_name"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="7dp"
android:gravity="center"
android:textSize="20sp"
android:textStyle="bold"/>
<TextView
android:id="#+id/preview_car_model"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"/>
</LinearLayout>
<TextView
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:background="#android:color/darker_gray"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/preview_part_name"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="7dp"
android:gravity="center"
android:textSize="20sp"
android:textStyle="bold"/>
<TextView
android:id="#+id/preview_part_model"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="7dp"
android:gravity="center"/>
<TextView
android:layout_width="1dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#android:color/darker_gray"
android:text="12"/>
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center_horizontal"
android:src="#drawable/car_part"/>
</LinearLayout>
<TextView
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:background="#android:color/darker_gray"/>
<LinearLayout
android:layout_width="70dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:orientation="vertical">
<TextView
android:id="#+id/preview_quantity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/holo_green_light"
android:gravity="center"
android:textSize="25sp"
android:layout_gravity="center"/>
<TextView
android:id="#+id/preview_quantity_bucket"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="15dp"
android:gravity="center"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_margin="15dp"
android:orientation="vertical">
<TextView
android:id="#+id/preview_extra_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:gravity="center"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="15dp">
<TextView
android:id="#+id/preview_ordered_from"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:textColor="#android:color/holo_red_light"/>
<TextView
android:id="#+id/preview_list_price"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:gravity="center"/>
<TextView
android:id="#+id/preview_list_less"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:gravity="right"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
Now in your adapter just create an arraylist with getters and setters that will save the card view object when ever it calls onBindViewHolder is called as below.
private static ArrayList<CardView> cardViewArrayList = new ArrayList<>();
#Override
public void onBindViewHolder(final PreviewOrderAdapter.MyViewHolder holder, int position)
{
OrderItemDetailsModel orderItemDetailsModel = namesArrList.get(position);
holder.orderedFrom.setText(orderItemDetailsModel.getOrderedFrom());
holder.listPrice.setText(orderItemDetailsModel.getListPrice());
holder.listLess.setText(orderItemDetailsModel.getListLess());
// ADDING THE CARD VIEW OBJECT IN THE ARRAYLIST
addCardView(holder.cardView);
}
#Override
public int getItemCount()
{
return namesArrList.size();
}
private static void addCardView(CardView cardView)
{
cardViewArrayList.add(cardView);
}
public static ArrayList<CardView> getCardViewList()
{
return cardViewArrayList;
}
Now finally, while printing the recycler views do this.
//Getting the card view array list from the adapter above
ArrayList<CardView> cardViewArrayList = adapter.getCardViewList();
for (int i = 0; i < cardViewArrayList.size(); i++)
{
// Iterate till the last of the array list and add each view individually to the document.
addContent(document, cardViewArrayList.get(i));
}
//Adding the content to the document
private void addContent(Document document, View view)
throws DocumentException
{
try
{
view.buildDrawingCache();
Bitmap bmp = view.getDrawingCache();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
Image image = Image.getInstance(stream.toByteArray());
image.scalePercent(70);
image.setAlignment(Image.MIDDLE);
document.add(image);
}
catch (Exception ex)
{
Log.e("TAG-ORDER PRINT ERROR", ex.getMessage());
}
}
By this way we dont have to worry about memory leaks due to the large size of the recycler view as we are adding each view separately to the document.
I have my information posted already on parse database but i want to retrieve it using recircularView.
can anyone please guide me or direct me on how should i do it?
here is my code of the xml that holds the layout of the recircularView
<?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="match_parent"
android:layout_marginBottom="#dimen/size_byte"
android:layout_marginLeft="#dimen/size_word"
android:layout_marginRight="#dimen/size_word"
android:layout_marginTop="#dimen/size_byte">
<ImageView
android:id="#+id/adPic"
android:layout_width="#dimen/movie_thumbnail_width"
android:layout_height="#dimen/movie_thumbnail_height"
android:layout_centerVertical="true"
android:src="#mipmap/ic_launcher" />
<TextView
android:id="#+id/adTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/adPic"
android:layout_marginLeft="56dp"
android:alpha="0.87"
android:gravity="right"
android:padding="#dimen/size_half_byte"
android:text="Hitman Agent 47"
android:textSize="#dimen/size_text_primary" />
<TextView
android:id="#+id/adPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#id/adTitle"
android:alpha="0.87"
android:padding="#dimen/size_half_byte"
android:text="5.00$"
android:textSize="#dimen/size_text_secondary" />
<TextView
android:id="#+id/adDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#id/adPrice"
android:alpha="0.87"
android:padding="#dimen/size_half_byte"
android:text="31-31-31"
android:textSize="#dimen/size_text_secondary" />
</RelativeLayout>
You can get the image url from ParseObject using getUrl() method of ParseFile
Suppose you get a list of ParseObjects like this
List<MyObject> myObjects = nee ArrayList();
List<ParseObject> objects
for (ParseObject objectItem: objects) {
String fileName = "";
String fileURL = "";
if (objectItem.getParseFile("imageColumn") != null) {
try {
ParseFile parseFile = (ParseFile) objectItem
.getParseFile("imageColumn");
fileURL = parseFile.getUrl();
fileName = parseFile.getName();
myObjects.add(new MyObject(fileName,fileURL));
} catch (Exception e) {
}
}
}
Later in your getView use the file URL to get the image only for the visible items in the listview. Such that your listview wont crash.
In my application , one Relative Layout has totally three ImageView()'s . I want to save all the three imageviews as a single .png file to the device storage on a single button click.
My code:
Layout XML :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/make" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="300dp"
android:layout_above="#+id/button1"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="#drawable/am0" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:text="Save Meme"
android:textStyle="bold"
android:textColor="#color/wt" />
<ImageView
android:id="#+id/top"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginTop="64dp"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/down"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageView1"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="74dp"
android:src="#drawable/ic_launcher" />
Activity Code :
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.sm);
main1 = (ImageView) findViewById(R.id.imageView1);
top = (ImageView) findViewById(R.id.top);
down = (ImageView) findViewById(R.id.down);
Bundle rec = getIntent().getExtras();
int rec1 = getIntent().getExtras().getInt("ams0");
Bitmap bmp = (Bitmap) rec.getParcelable("bm0");
Bitmap bmp1 = (Bitmap) rec.getParcelable("bm1");
main1.setImageResource(rec1);
top.setImageBitmap(bmp);
down.setImageBitmap(bmp1);
}
How do I save the image views as a file ?
Try using a Сanvas
Bitmap mainBitmap = ((BitmapDrawable)main1.getDrawable()).getBitmap().copy(Bitmap.Config.ARGB_8888, true);
Canvas canvas = new Canvas(mainBitmap);
canvas.drawBitmap(bmp.copy(Bitmap.Config.ARGB_8888, true), 1, 1, null);
canvas.drawBitmap(bmp1.copy(Bitmap.Config.ARGB_8888, true), 1, 1, null);
OutputStream os = null;
try {
os = new FileOutputStream("/sdcard/DCIM/Camera/myImages.png");
mainBitmap.compress(Bitmap.CompressFormat.PNG, 50, os);
} catch (IOException e) {
e.printStackTrace();
}
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.