tvNext.setOnClickListener giving ERROR - android

ERROR LINE:java.lang.NullPointerException: Attempt to invoke virtual
method 'void android.widget.ImageView.setOnClickListener(android.view.View$OnClickListener)'
on a null object reference
.JAVA FILE
package co.hangyr.Hangyr.Activity.Camera;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.hardware.Camera;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import butterknife.ButterKnife;
import butterknife.InjectView;
import co.hangyr.Hangyr.Activity.Home.ActivityHome;
import co.hangyr.Hangyr.Activity.Others.Footer;
import co.hangyr.Hangyr.R;
public class ActivityCamera extends Footer implements View.OnClickListener {
static final int RESULT_LOAD_IMAGE = 1;
private Camera mCamera;
private CameraPreview mCameraPreview;
ImageView imageView;
/* static final int SECOND_PIC = 2;
static final int THIRD_PIC = 3;
static final int FORTH_PIC = 4;
static final int FIFTH_PIC = 5;
*/
#InjectView(R.id.ivFirstPic)
ImageView firstPic;
#InjectView(R.id.ivCapture)
ImageView ivCapture;
#InjectView(R.id.ivFlipCamera)
ImageView flipCamera;
#InjectView(R.id.ivFlash)
ImageView flash;
#InjectView(R.id.tvUploadFromGallery)
TextView tvUploadFromGallery;
#InjectView(R.id.ivSecondPic)
ImageView secondPic;
#InjectView(R.id.ivThirdPic)
ImageView thirdPic;
#InjectView(R.id.ivForthPic)
ImageView forthPic;
#InjectView(R.id.ivFifthPic)
ImageView fifthPic;
#InjectView(R.id.ivJustClicked)
FrameLayout justClicked;
// #InjectView(R.id.tvNextEditPic)
TextView tvNext;
#InjectView(R.id.bDeleteFirstPic)
Button deleteFirstPic;
#InjectView(R.id.bDeleteSecondPic)
Button deleteSecondPic;
#InjectView(R.id.bDeleteThirdPic)
Button deleteThirdPic;
#InjectView(R.id.bDeleteForthPic)
Button deleteForthPic;
#InjectView(R.id.bDeleteFifthPic)
Button deleteFifthPic;
#InjectView(R.id.tvCancel)
TextView tvCancel;
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.camera);
ButterKnife.inject(this);
tvNext = (TextView) findViewById(R.id.tvNextEditPic);
tvNext.setOnClickListener(this);
mCamera = getCameraInstance();
mCamera.setDisplayOrientation(90);
mCameraPreview = new CameraPreview(this, mCamera);
justClicked.addView(mCameraPreview);
ivCapture.setOnClickListener(this);
tvUploadFromGallery.setOnClickListener(this);
firstPic.setOnClickListener(this);
deleteFirstPic.setOnClickListener(this);
deleteSecondPic.setOnClickListener(this);
deleteThirdPic.setOnClickListener(this);
deleteForthPic.setOnClickListener(this);
deleteFifthPic.setOnClickListener(this);
tvCancel.setOnClickListener(this);
}
private Camera getCameraInstance() {
Camera camera = null;
try {
camera = Camera.open();
flipCamera.setVisibility(View.VISIBLE);
flash.setVisibility(View.VISIBLE);
} catch (Exception e) {
// cannot get camera or does not exist
}
return camera;
}
Camera.PictureCallback mPicture = new Camera.PictureCallback() {
#Override
public void onPictureTaken(byte[] data, Camera camera) {
File pictureFile = getOutputMediaFile();
if (pictureFile == null) {
return;
}
try {
FileOutputStream fos = new FileOutputStream(pictureFile);
Bitmap bmp = BitmapFactory.decodeByteArray(data, 0, data.length);
firstPic.setImageBitmap(bmp);
fos.write(data);
fos.close();
} catch (FileNotFoundException e) {
} catch (IOException e) {
}
}
};
private static File getOutputMediaFile() {
File mediaStorageDir = new File(
Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
"MyCameraApp");
if (!mediaStorageDir.exists()) {
if (!mediaStorageDir.mkdirs()) {
Log.d("MyCameraApp", "failed to create directory");
return null;
}
}
// Create a media file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss")
.format(new Date());
File mediaFile;
mediaFile = new File(mediaStorageDir.getPath() + File.separator
+ "IMG_" + timeStamp + ".jpg");
return mediaFile;
}
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.ivCapture:
mCamera.takePicture(null, null, mPicture);
break;
case R.id.ivFirstPic:
mCameraPreview.getHolder().removeCallback(mCameraPreview);
Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, RESULT_LOAD_IMAGE);
deleteFirstPic.setVisibility(View.VISIBLE);
break;
case R.id.tvCancel:
startActivity(new Intent(getApplicationContext(), ActivityHome.class));
break;
case R.id.tvNextEditPic:
startActivity(new Intent(getApplicationContext(), UploadPic.class));
break;
case R.id.bDeleteFirstPic:
firstPic.setImageResource(R.drawable.pic_item_cam);
deleteFirstPic.setVisibility(View.GONE);
break;
case R.id.bDeleteSecondPic:
secondPic.setImageResource(R.drawable.pic_item_cam);
deleteSecondPic.setVisibility(View.GONE);
break;
case R.id.bDeleteThirdPic:
thirdPic.setImageResource(R.drawable.pic_item_cam);
deleteThirdPic.setVisibility(View.GONE);
break;
case R.id.bDeleteForthPic:
forthPic.setImageResource(R.drawable.pic_item_cam);
deleteForthPic.setVisibility(View.GONE);
break;
case R.id.bDeleteFifthPic:
fifthPic.setImageResource(R.drawable.pic_item_cam);
deleteFifthPic.setVisibility(View.GONE);
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
Uri selectedImage = data.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
firstPic.setImageBitmap(BitmapFactory.decodeFile(picturePath));
}
}
}
.XML FILE
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/backgroundApp"
android:orientation="vertical"
android:weightSum="2">
<LinearLayout
android:id="#+id/llNameBack"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_marginBottom="1dp"
android:background="#color/white"
android:orientation="horizontal"
android:weightSum="2">
<TextView
android:id="#+id/tvCancel"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_gravity="left|center"
android:layout_marginBottom="15dp"
android:paddingLeft="15dp"
android:layout_marginTop="14dp"
android:layout_weight="1"
android:gravity="left|center_vertical"
android:text="#string/cancelS"
android:textColor="#color/black"
android:textSize="13dp"
android:textStyle="bold" />
<TextView
android:id="#+id/tvNextEditPic"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_gravity="end|center_vertical"
android:layout_marginBottom="15dp"
android:paddingRight="15dp"
android:layout_marginTop="14dp"
android:layout_weight="1"
android:background="#color/white"
android:gravity="right|center_vertical"
android:text="#string/nextS"
android:textColor="#fd676a"
android:textSize="13dp"
android:textStyle="bold" />
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="375dp">
<FrameLayout
android:id="#+id/ivJustClicked"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:layout_margin="5dp"
android:layout_weight="1">
<ImageView
android:id="#+id/ivFlipCamera"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|bottom"
android:padding="8dp"
android:src="#drawable/flip_camera" />
<ImageView
android:id="#+id/ivFlash"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|bottom"
android:padding="8dp"
android:src="#drawable/flash_icon" />
</FrameLayout>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:orientation="vertical">
<TextView
android:id="#+id/tvUploadFromGallery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/white"
android:padding="18dp"
android:text="#string/galleryS"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#4a4a4a"
android:textSize="13dp"
android:textStyle="bold" />
<ImageView
android:id="#+id/ivCapture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="16dp"
android:layout_marginTop="-30dp"
android:src="#drawable/capture" />
<include
layout="#layout/camera_pic_added"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginTop="1dp"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>

You should use #Bindinstead of #InjectView
#InjectView was replaced June 2015.

You missed to initialize this variable ivFirstPic:
ivFirstPic.setOnClickListener(this);

Related

How to retrieve data from the firebase and show inside the CardView nicely

I have created the CreateEvent.java module to upload the data to firebase. But how to retrieve the data and show in the Cardlist? For example show in the xml file below. And also if there was more than 1 data in firebase, how to show in with multiple cardlist that I have created in the xml file?
CreateEvent.java
package com.example.edward.eventmanagementsystem.ManageEvent;
import android.Manifest;
import android.app.DatePickerDialog;
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
import com.example.edward.eventmanagementsystem.R;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.firebase.storage.FirebaseStorage;
import com.google.firebase.storage.OnProgressListener;
import com.google.firebase.storage.StorageReference;
import com.google.firebase.storage.UploadTask;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;
import static android.widget.Toast.LENGTH_SHORT;
public class CreateEvent extends Activity {
private static final String TAG = "activity_create_event";
private Uri filePath;
private TextView mDisplayDate;
private DatePickerDialog.OnDateSetListener mDateSetListener;
private DatabaseReference mDatabaseReference;
private Button mRegisterButton;
EditText mEventNameText, mContactNumText, mEventLocationText;
TextView mEventDate;
RadioGroup mEventType;
FirebaseStorage storage;
StorageReference storageRef,imageRef;
ProgressDialog progressDialog;
UploadTask uploadTask;
Uri uriImage = Uri.parse("com.example.edward.eventmanagementsystem.ManageEvent/"+ R.drawable.ic_launcher_background);
public static final int PICK_IMAGE = 1;
ImageView mimageToUpload;
#Override
protected void onCreate(Bundle savedInstanceState) {
FirebaseDatabase firebaseDatabase;
mDatabaseReference = FirebaseDatabase.getInstance().getReference().child("ListEventInformation").push();
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_create_event);
mRegisterButton = (Button)findViewById(R.id.btnRegisterEvent);
storage = FirebaseStorage.getInstance();
storageRef = storage.getReference();
mDisplayDate = (TextView) findViewById(R.id.RegisterEventStartDate);
mDisplayDate.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Calendar cal = Calendar.getInstance();
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH);
int day = cal.get(Calendar.DAY_OF_MONTH);
DatePickerDialog dialog = new DatePickerDialog(
CreateEvent.this,
android.R.style.Theme_Holo_Light_Dialog_MinWidth,
mDateSetListener,
year, month, day);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.show();
}
});
mDateSetListener = new DatePickerDialog.OnDateSetListener() {
#Override
public void onDateSet(DatePicker view, int year, int month, int day) {
month = month + 1;
Log.d(TAG, "onDateSet: date: mm/dd/yyyy: " + month + "/" + day + "/" + year);
String date = month + "/" + day + "/" + year;
mDisplayDate.setText(date);
}
};
//perform action upload image
mimageToUpload = (ImageView) findViewById(R.id.imageToUpload);
//insert data to database
mEventNameText = (EditText) findViewById(R.id.RegisterEventName);
mContactNumText = (EditText) findViewById(R.id.RegisterContactNumber);
mEventDate = (TextView) findViewById(R.id.RegisterEventStartDate);
mEventType = (RadioGroup) findViewById(R.id.RegisterEventRadiogroup);
mEventLocationText = (EditText) findViewById(R.id.RegisterEventLocation);
mimageToUpload = (ImageView) findViewById(R.id.imageToUpload);
mRegisterButton = (Button) findViewById(R.id.btnRegisterEvent);
mimageToUpload.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (ContextCompat.checkSelfPermission(CreateEvent.this, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED){
selectPdf();
}
else {
ActivityCompat.requestPermissions(CreateEvent.this,new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},9);
}
}
});
mRegisterButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
int selectedId = mEventType.getCheckedRadioButtonId();
RadioButton radioButton = (RadioButton)findViewById(selectedId);
final String name = mEventNameText.getText().toString().trim();
final String contact = mContactNumText.getText().toString().trim();
final String date = mEventDate.getText().toString().trim();
final String type = radioButton.getText().toString().trim();
final String location = mEventLocationText.getText().toString().trim();
if (TextUtils.isEmpty(name)) {
mEventNameText.setError("Enter First Name!");
return;
}
if (TextUtils.isEmpty(date)) {
mEventDate.setError("Enter Date!");
return;
}
if (TextUtils.isEmpty(type)) {
radioButton.setError("Enter Phone Number!");
return;
}
if(isValidPhone(contact)){
Toast.makeText(getApplicationContext(),"Phone number is valid",Toast.LENGTH_SHORT).show();
}else {
mContactNumText.setError("Phone number is not valid");
Toast.makeText(getApplicationContext(),"Phone number is not valid",Toast.LENGTH_SHORT).show();
return;
}
if (TextUtils.isEmpty(location)) {
mEventLocationText.setError("Enter Location!");
return;
}
Map userInfo = new HashMap();
userInfo.put("mEventNameText", name);
userInfo.put("mContactNumText", contact);
userInfo.put("mEventDate", date);
userInfo.put("radioButton", type);
userInfo.put("mEventLocationText", location);
mDatabaseReference.updateChildren(userInfo);
final String fileName = System.currentTimeMillis()+"";
if(uriImage != null) {
StorageReference storageReference = storage.getReference();
storageReference.child("profileImageUrl").child(fileName).putFile(uriImage)
.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
#Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
String url = taskSnapshot.getMetadata().getReference().getDownloadUrl().toString();
mDatabaseReference.child("profileImageUrl").setValue(url).addOnCompleteListener(new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task) {
if (task.isSuccessful()){ }
else{
Toast.makeText(getApplicationContext(),"File not Successfully Uploaded",LENGTH_SHORT).show(); }
}
});
}
}).addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
Toast.makeText(getApplicationContext(),"File not Successfully Uploaded",LENGTH_SHORT).show();
}
}).addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
#Override
public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {
}
});
}else{
}
Toast.makeText(getApplicationContext(),"New event created successfully!",LENGTH_SHORT).show();
Intent ManageEventMenu = new Intent(CreateEvent.this, com.example.edward.eventmanagementsystem.ManageEvent.ManageEventMenu.class);
startActivity(ManageEventMenu);
}
});
}
public boolean isValidPhone(CharSequence phone) {
boolean check=false;
if(!Pattern.matches("[a-zA-Z]+", phone))
{
if(phone.length() < 10 || phone.length() > 11)
{
check = false;
}
else
{
check = true;
}
}
else
{
check=false;
}
return check;
}
private void selectPdf() {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_OPEN_DOCUMENT);
startActivityForResult(intent,86);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 86 && resultCode == RESULT_OK && data != null){
final Uri imageUri = data.getData();
uriImage = imageUri;
mimageToUpload.setImageURI(uriImage);
}
else {
Toast.makeText(getApplicationContext(),"Please select file", LENGTH_SHORT).show();
}
}
}
I would like to show the data in this way.
The sample of xml file I would like to display the data create from Firebase in upload from CreateEvent.java
activity_list_of_event.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical"
android:background="#drawable/gradientwallpaper">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Events"
android:layout_marginLeft="10dp"
android:textStyle="bold"
android:layout_marginTop="20dp"
android:textSize="24dp"
android:textColor="#color/white"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Total Created Event"
android:layout_marginLeft="10dp"
android:textSize="16dp"
android:textColor="#color/white"
android:layout_marginTop="10dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10dp"
android:layout_marginBottom="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Upcoming"
android:layout_marginLeft="10dp"
android:textSize="16dp"
android:textColor="#color/white"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Pass"
android:gravity="right"
android:layout_marginRight="10dp"
android:textSize="16dp"
android:textColor="#color/white"/>
</LinearLayout>
<android.support.v7.widget.CardView 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="wrap_content"
android:layout_margin="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:padding="10dp"
android:weightSum="10">
<LinearLayout
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="4"
android:orientation="vertical">
<TextView
android:id="#+id/item_month"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Month" />/ android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
<TextView
android:id="#+id/item_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Date" />/ android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
</LinearLayout>
<LinearLayout
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:orientation="vertical">
<TextView
android:id="#+id/item_eventName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Event Name"
android:textStyle="bold" />/android:textScaleX="18sp"
<TextView
android:id="#+id/item_contactNumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Contact Number"
android:textStyle="bold" />
<TextView
android:id="#+id/item_type"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Type of event"
android:textStyle="bold" />
<TextView
android:id="#+id/itemLocation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Location"
android:textStyle="bold" />
</LinearLayout>
<ImageView
android:id="#+id/item_image"
android:layout_width="75dp"
android:layout_height="75dp"
android:background="#color/white"
android:scaleType="centerCrop"
android:src="#drawable/pic1" />
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>

Video not playing in video view - Surface View

I am trying to play a video in a videoview and want to show the live camera feed from the device in the background surface view.But the problem is Surface view overlays the videoview hiding it totally and video is not playing properly in videoview rather sound alone playing. Can anyone help me with this please?
Activity XML code:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<SurfaceView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/surfaceView"/>
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="20dp"
android:background="#drawable/seekbar_video"
android:id="#+id/progressBar" />
<ImageButton
android:layout_alignParentLeft="true"
android:layout_marginLeft="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00000000"
android:layout_marginTop="20dp"
android:src="#drawable/ic_close_3x"
android:textSize="18dp"
android:textAllCaps="false"
android:layout_below="#+id/progressBar"
android:drawableLeft="#drawable/ic_back_3x"
android:id="#+id/close"
/>
<ImageButton
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00000000"
android:layout_marginTop="20dp"
android:src="#drawable/ic_right_3x"
android:layout_below="#+id/progressBar"
android:textSize="18dp"
android:layout_marginRight="20dp"
android:textAllCaps="false"
android:id="#+id/next"
android:visibility="invisible"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RECORD"
android:layout_marginTop="100dp"
android:textColor="#ffffff"
android:gravity="center"
android:layout_centerHorizontal="true"
android:textSize="25dp"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="300dp"
android:background="#ffffff"
android:gravity="center"
android:orientation="vertical"
android:layout_marginTop="140dp"
android:id="#+id/linearLayout">
<VideoView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/memix_video"
/>
</LinearLayout>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00000000"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="50dp"
android:id="#+id/camera"
android:src="#drawable/ic_frontcamera_3x"
android:layout_marginBottom="40dp"
/>
<ImageButton
android:id="#+id/record"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/circle_bg"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="20dp"
android:src="#drawable/ic_video"
/>
<ImageButton
android:id="#+id/record_large"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#drawable/circle_bg"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="20dp"
android:src="#drawable/ic_video"
android:visibility="invisible"
/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00000000"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginRight="50dp"
android:src="#drawable/ic_undo_3x"
android:id="#+id/undo"
android:layout_marginBottom="40dp"
/>
</RelativeLayout>
</FrameLayout>
Java File:
import android.Manifest;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.hardware.Camera;
import android.media.MediaRecorder;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.view.Menu;
import android.view.MenuItem;
import android.view.SurfaceHolder;
import android.view.SurfaceHolder.Callback;
import android.view.SurfaceView;
import android.hardware.Camera.Parameters;
import android.media.MediaPlayer;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import android.widget.VideoView;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class MemixActivity extends AppCompatActivity implements Callback{
VideoView videoView;
private static final int MY_PERMISSIONS_REQUEST_ACCOUNTS = 1;
File appDir = new File(Environment.getExternalStorageDirectory()+File.separator+"Memecry/temp");
String filepath=appDir.getAbsolutePath()+"/trim.mp4";
private SurfaceView mPreview;
private Camera mCamera;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_memix);
Log.e("file",filepath);
videoView=(VideoView)findViewById(R.id.memix_video) ;
mPreview=(SurfaceView)findViewById(R.id.surfaceView);
videoView.setVideoPath("/storage/emulated/0/Memecry/temp/trim.mp4");
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
mp.setLooping(true);
mp.start();
int duration=mp.getDuration();
Log.e("dur", String.valueOf(duration));
}
});
mPreview = (SurfaceView)findViewById(R.id.surfaceView);
if( checkAndRequestPermissions()) {
Log.e("camera","Camera Started");
mPreview.getHolder().addCallback(this);
mPreview.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
mCamera = Camera.open();
}
}
private boolean checkAndRequestPermissions() {
int permissionCAMERA = ContextCompat.checkSelfPermission(this,
Manifest.permission.CAMERA);
int storagePermission = ContextCompat.checkSelfPermission(this,
Manifest.permission.RECORD_AUDIO);
List<String> listPermissionsNeeded = new ArrayList<>();
if (storagePermission != PackageManager.PERMISSION_GRANTED) {
listPermissionsNeeded.add(Manifest.permission.RECORD_AUDIO);
}
if (permissionCAMERA != PackageManager.PERMISSION_GRANTED) {
listPermissionsNeeded.add(Manifest.permission.CAMERA);
}
if (!listPermissionsNeeded.isEmpty()) {
ActivityCompat.requestPermissions(this,
listPermissionsNeeded.toArray(new String[listPermissionsNeeded.size()]), MY_PERMISSIONS_REQUEST_ACCOUNTS);
return false;
}
return true;
}
#Override public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
switch (requestCode) {
case MY_PERMISSIONS_REQUEST_ACCOUNTS:
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
//Permission Granted Successfully. Write working code here.
mPreview.getHolder().addCallback(this);
mPreview.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
mCamera = Camera.open();
} else {
//You did not accept the request can not use the functionality.
checkAndRequestPermissions();
}
break;
}
}
#Override
public void surfaceCreated(SurfaceHolder holder) {
try {
mCamera.setPreviewDisplay(mPreview.getHolder());
} catch (Exception e) {
e.printStackTrace();
}
}
#Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
Camera.Parameters params = mCamera.getParameters();
List<Camera.Size> sizes = params.getSupportedPreviewSizes();
Camera.Size selected = sizes.get(0);
params.setPreviewSize(selected.width,selected.height);
mCamera.setParameters(params);
mCamera.startPreview();
}
#Override
public void surfaceDestroyed(SurfaceHolder holder) {
Log.i("PREVIEW","surfaceDestroyed");
}
}
I did it by adding setZOrderOnTop(true) for the videoview to bring it front and it's working perfectly.

Share text and image with android intent

That is my code java
intent.putExtra(Intent.EXTRA_SUBJECT, "My App name and some text");
intent.putExtra(Intent.EXTRA_TEXT, "a link");
intent.putExtra(Intent.EXTRA_STREAM,getImageUri(context,mBitmap));
intent.setType("image/*,text/plain");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
I want to share image and text. This code works on WhatsApp, Twitter, Gmail , etc .. but it does not work on Facebook
thank you in advance for your help
If you want to share the Image and text on Facebook without using Facebook SDK then you have to create the bitmap of your image plus text and then you can share that bitmap on facebook.
Download the source code from here (Share image and text on facebook using intent in android)
activity_main.xml
<RelativeLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
xmlns:android="http://schemas.android.com/apk/res/android">
<EditText
android:id="#+id/et_text"
android:layout_width="match_parent"
android:textSize="15dp"
android:layout_height="45dp"
android:layout_marginTop="10dp"
android:background="#drawable/edittext_drawable"
android:hint="Enter your text"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:paddingRight="10dp"
android:inputType="text"
android:imeOptions="actionDone"
android:paddingLeft="10dp"
android:singleLine="true"
android:textColorHint="#979797" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/rl_main"
android:background="#ffffff"
android:layout_below="#+id/et_text"
android:layout_above="#+id/tv_share">
<ImageView
android:layout_width="match_parent"
android:layout_height="250dp"
android:src="#drawable/index"
android:scaleType="fitXY"
android:id="#+id/iv_image"
android:layout_marginTop="10dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15dp"
android:id="#+id/tv_text"
android:layout_below="#+id/iv_image"
android:layout_margin="10dp"
android:textColor="#000000"
android:maxLines="5"
/>
</RelativeLayout>
<TextView
android:id="#+id/tv_share"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#F38D0A"
android:gravity="center"
android:padding="10dp"
android:layout_margin="10dp"
android:text="Share"
android:textColor="#ffffff"
android:textSize="15dp"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
MainActivity.java
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
EditText et_text;
ImageView iv_image;
TextView tv_share,tv_text;
RelativeLayout rl_main;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
}
private void init(){
et_text = (EditText)findViewById(R.id.et_text);
iv_image = (ImageView)findViewById(R.id.iv_image);
tv_share = (TextView)findViewById(R.id.tv_share);
rl_main = (RelativeLayout)findViewById(R.id.rl_main);
tv_text= (TextView) findViewById(R.id.tv_text);
File dir = new File("/sdcard/Testing/");
try {
if (dir.mkdir()) {
System.out.println("Directory created");
} else {
System.out.println("Directory is not created");
}
} catch (Exception e) {
e.printStackTrace();
}
tv_share.setOnClickListener(this);
et_text.addTextChangedListener(new TextWatcher() {
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
#Override
public void afterTextChanged(Editable s) {
tv_text.setText(et_text.getText().toString());
}
});
}
#Override
public void onClick(View v) {
switch (v.getId()){
case R.id.tv_share:
Bitmap bitmap1 = loadBitmapFromView(rl_main, rl_main.getWidth(), rl_main.getHeight());
saveBitmap(bitmap1);
String str_screenshot = "/sdcard/Testing/"+"testing" + ".jpg";
fn_share(str_screenshot);
break;
}
}
public void saveBitmap(Bitmap bitmap) {
File imagePath = new File("/sdcard/Testing/"+"testing" + ".jpg");
FileOutputStream fos;
try {
fos = new FileOutputStream(imagePath);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
fos.flush();
fos.close();
Log.e("ImageSave", "Saveimage");
} catch (FileNotFoundException e) {
Log.e("GREC", e.getMessage(), e);
} catch (IOException e) {
Log.e("GREC", e.getMessage(), e);
}
}
public static Bitmap loadBitmapFromView(View v, int width, int height) {
Bitmap b = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
v.draw(c);
return b;
}
public void fn_share(String path) {
File file = new File("/mnt/" + path);
Bitmap bmp = BitmapFactory.decodeFile(file.getAbsolutePath());
Uri uri = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(intent, "Share Image"));
}
}
Thanks!
You can share int value of an image as R.drawable.image and get it with getResources.getDrawable(int)

picture returning to app is sideways

making a simple app, the problem I am having now is that when im using an intent to launch the camera app to take a picture, the app is supposed to take the picture and overwrite the imageview which was for the background image. What its doing is bring the freshly taken picture and displaying it sideways.
this is my main java file:
package com.example.piktuur;
import java.io.File;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.view.Menu;
import android.view.View;
import android.widget.ImageView;
import android.widget.SeekBar;
public class PiktuurMain extends Activity {
private Uri outputFileUri;
private static int TAKE_PICTURE = 1;
private ImageView image;
private SeekBar adjust;
public int height, width;
public boolean proceede;
public File file;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.piktuur_main);
image = (ImageView) findViewById(R.id.imageView1);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.piktuur_main, menu);
return true;
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == TAKE_PICTURE && resultCode == RESULT_OK) {
BitmapFactory.Options options = new BitmapFactory.Options();
String file = Environment.getExternalStorageDirectory() + "/image.png";
Bitmap bitmap = BitmapFactory.decodeFile(file, options);
image.setImageBitmap(bitmap);
}
}
public void cameraClicked(View V){
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File file = new File(Environment.getExternalStorageDirectory(), "image.png");
outputFileUri = Uri.fromFile(file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(intent, TAKE_PICTURE);
}
public void shareClicked(View V){
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_EMAIL, "stephen.w.protzman#gmail.com");
intent.putExtra(Intent.EXTRA_SUBJECT, "Piktuur");
intent.putExtra(Intent.EXTRA_TEXT, "Here is a picture for you!");
startActivity(Intent.createChooser(intent, "Send Email"));
}
}
and here is the main xml with the imageview in it:
<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=".PiktuurMain" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:scaleType="fitXY"
android:src="#drawable/pic" />
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="5dp" >
<ImageButton
android:id="#+id/takepic"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#drawable/round"
android:onClick="cameraClicked"
android:src="#android:drawable/ic_menu_camera" />
<ImageButton
android:id="#+id/editpic"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_weight="1"
android:background="#drawable/round"
android:src="#android:drawable/ic_menu_edit" />
<ImageButton
android:id="#+id/sharepic"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#drawable/round"
android:onClick="shareClicked"
android:src="#android:drawable/ic_menu_share" />
</LinearLayout>
<SeekBar
android:id="#+id/seekBar1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/linearLayout1"
android:layout_alignParentLeft="true" />
</RelativeLayout>
I have zero ideas why this is happening any clue?
try this
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK)
{
Uri imageUri = data.getData();
Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), imageUri);
image.setImageBitmap(bitmap);
}
}

Selecting image for imageview1 at left and imageview2 at right fixed

I'm still new here in android. Please help me. I manage to put the imageview to the left and right side of my Layout. My problem is when I select an image for imageview2 it passes the image to imageview1 and still the imageview2 can be seen from the right side.
I need to do is when I select an image for imageview2 it should be fixed at the right side. I think I have problems with my code in java?
Here is my code for xml.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/insert_bg"
>
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="15dip"
android:paddingBottom="15dip"
>
<ImageView
android:id="#+id/img_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:fitsSystemWindows="false"
android:scaleType="fitStart"
android:src="#drawable/insert_ci" />
<ImageView
android:id="#+id/img_center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
android:fitsSystemWindows="false"
android:scaleType="fitEnd"
android:src="#drawable/insert_ci"
android:textAlignment="viewEnd" />
</LinearLayout>
And this code for java.
package com.prototype;
import java.io.File;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
//import android.widget.ImageButton;
import android.widget.ImageView;
//import android.widget.LinearLayout;
public class MainActivity3 extends Activity {
private static final int SELECT_PICTURE = 2;
private String selectedImagePath;
private String selectedImagePath2;
private ImageView img;
private ImageView img2;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.open_project);
img = (ImageView)findViewById(R.id.img_left);
img2= (ImageView)findViewById(R.id.img_center);
addImageViewClickListener();
addImageView2ClickListener();
}
public void addImageViewClickListener()
{
ImageView btnNavigator1 = (ImageView)findViewById(R.id.img_left);
btnNavigator1.setOnClickListener(new OnClickListener()
{
public void onClick(View arg0)
{
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select character image for right side."), SELECT_PICTURE);
}
//#Override
//public void onClick(View v) {
// TODO Auto-generated method stub
//}
});
}
public void addImageView2ClickListener()
{
ImageView btnNavigator2 = (ImageView)findViewById(R.id.img_center);
btnNavigator2.setOnClickListener(new OnClickListener()
{
public void onClick(View arg0)
{
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select character image for left side."), SELECT_PICTURE);
}
//#Override
//public void onClick(View v) {
// TODO Auto-generated method stub
//}
});
}
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (resultCode == RESULT_OK)
{
if (requestCode == SELECT_PICTURE)
{
//File folder = new File(Environment.getExternalStorageDirectory() + "/Database/");
Uri selectedImageUri = data.getData();
selectedImagePath = getPath(selectedImageUri);
System.out.println("Image Path : " + selectedImagePath);
img.setImageURI(selectedImageUri);
}
}
}
public void onActivityResult2(int requestCode, int resultCode, Intent data)
{
if (resultCode == RESULT_OK)
{
if (requestCode == SELECT_PICTURE)
{
//File folder = new File(Environment.getExternalStorageDirectory() + "/Database/");
Uri selectedImageUri = data.getData();
selectedImagePath2 = getPath(selectedImageUri);
System.out.println("Image Path : " + selectedImagePath2);
img2.setImageURI(selectedImageUri);
}
}
}
public String getPath(Uri uri) {
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(uri, projection, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
The problem that I was talking about is like this.http://imageshack.us/photo/my-images/31/6sa6.png/
printscreen image
Use this for two imageViews. So your images will not overlap
android:adjustViewBounds="true"
android:scaleType="fitXY
Try this one,
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".MainActivity" >
<ImageView
android:id="#+id/img_left"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:fitsSystemWindows="false"
android:scaleType="fitXY"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/img_center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:fitsSystemWindows="false"
android:scaleType="fitXY"
android:src="#drawable/ic_launcher"
android:textAlignment="viewEnd" />
</LinearLayout>
The image is getting stretched because of the weight mentioned.
The android:layout_weight for the first imageView is 1 and that is for second imageView is 2.
This leads to taking 2/3rd of the screen by the the second imageView and the rest by the first.
Adjust the weights and you can overcome the issue.
Change your Imageview make 0dp to your android:layout_width#
<ImageView
android:id="#+id/img_left"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:fitsSystemWindows="false"
android:scaleType="fitStart"
android:src="#drawable/icon" />
<ImageView
android:id="#+id/img_center"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:fitsSystemWindows="false"
android:scaleType="fitEnd"
android:src="#drawable/icon"
android:textAlignment="viewEnd" />
Update
Create one more folder named layout-land and keep same xml inside with appropriate changes, hope it works.

Categories

Resources