Я захват изображения с камеры и отправить его на сервер .Я отображения захваченного изображения на фоне RelativeLayout
используя следующий код:Изображение растягивается при установке в качестве фона в относительной макете
private void previewMedia(boolean isImage) {
// Checking whether captured media is image or video
if (isImage) {
Log.e("Preview Media", "Called");
BitmapFactory.Options options = new BitmapFactory.Options();
// down sizing image as it throws OutOfMemory Exception for larger images
options.inSampleSize = 8;
//options.inScaled = false;
Log.e("File URI", String.valueOf(fileUri));
final Bitmap bitmap = BitmapFactory.decodeFile(fileUri.getPath(), options);
//Uploading image to server
new UploadFileToServer().execute();
Log.e("DownSizing image", "Called");
Drawable dr = new BitmapDrawable(bitmap);
Log.e("DrawableN", String.valueOf(dr));
relativeLayout.setBackgroundDrawable(dr);
}
}
Внутри код, я сокращение изображения, чтобы избежать OutOfMemory Exception
.WHILE настройки изображения в background
относительной макете, изображение получил stretched.Screenshot приводится ниже:
Код XML:
<?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:padding="@dimen/padding10">
<RelativeLayout
android:id="@+id/rel"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_marginBottom="@dimen/margin10"
android:layout_marginLeft="@dimen/margin10"
android:layout_marginRight="@dimen/margin10"
android:layout_marginTop="@dimen/margin10">
<ImageView
android:id="@+id/arrowProfile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:paddingLeft="@dimen/padding10"
android:src="@drawable/back_signup" />
<com.almabay.almachat.circularImageView.CircularImageView
android:id="@+id/cam"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentRight="true"
android:paddingRight="@dimen/padding10"
android:background="@drawable/camera1"/>
<TextView
android:id="@+id/userName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/status"
android:layout_alignParentBottom="true"
android:layout_marginBottom="@dimen/margin20"
android:paddingLeft="@dimen/padding10"
android:text="User Name"
android:textColor="#ffffff"
android:textSize="20sp" />
<TextView
android:id="@+id/status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:paddingLeft="@dimen/padding10"
android:text="Status of user"
android:textColor="#ffffff" />
</RelativeLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/rel"
android:background="@color/divider_background">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginRight="@dimen/margin10"
android:layout_marginTop="@dimen/margin10"
android:background="@color/divider_background"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="@dimen/margin10"
android:background="#ffffff"
android:orientation="vertical"
android:paddingLeft="@dimen/padding10">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="First Name"
android:textStyle="bold" />
<TextView
android:id="@+id/firstNameProfile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ashish" />
<View
android:layout_width="match_parent"
android:layout_height="@dimen/divider_height"
android:layout_marginBottom="@dimen/margin10"
android:layout_marginTop="@dimen/margin10"
android:background="@color/divider_background" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Last Name"
android:textStyle="bold" />
<TextView
android:id="@+id/lastNameProfile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Kumar" />
<View
android:layout_width="match_parent"
android:layout_height="@dimen/divider_height"
android:layout_marginBottom="@dimen/margin10"
android:layout_marginTop="@dimen/margin10"
android:background="@color/divider_background" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Birthday"
android:textStyle="bold" />
<TextView
android:id="@+id/birthday"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="03 December" />
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_marginBottom="@dimen/margin10"
android:layout_marginTop="@dimen/margin10"
android:background="@color/divider_background" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Gender"
android:textStyle="bold" />
<TextView
android:id="@+id/gender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/padding10"
android:text="Female" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="@dimen/margin10"
android:background="@color/while_color"
android:orientation="vertical"
android:paddingLeft="@dimen/padding10">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:paddingTop="@dimen/padding10"
android:text="Status"
android:textStyle="bold" />
<ImageView
android:id="@+id/imgEdit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="@dimen/divider_height"
android:layout_marginBottom="@dimen/margin10"
android:layout_marginTop="@dimen/margin10"
android:background="@color/divider_background" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/padding10"
android:text="Displaying the status message here" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="@dimen/margin10"
android:background="@color/while_color"
android:orientation="vertical"
android:paddingLeft="@dimen/padding10">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="Email"
android:textStyle="bold" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="@dimen/divider_height"
android:layout_marginBottom="@dimen/margin10"
android:layout_marginTop="@dimen/margin10"
android:background="@color/divider_background" />
<TextView
android:id="@+id/emailProfile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/padding10"
android:text="Email ID" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="@dimen/margin10"
android:background="@color/while_color"
android:orientation="vertical"
android:paddingLeft="@dimen/padding10">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="@dimen/padding10">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="Phone"
android:textStyle="bold" />
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentRight="true" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="@dimen/divider_height"
android:layout_marginBottom="@dimen/margin10"
android:background="@color/divider_background" />
<TextView
android:id="@+id/mobile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/padding10"
android:text="13464646466" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
Пожалуйста, помогите исправить issue.I я использую ширину, как match_parent и высоты, как 150dp для RelativeLayout.
вместо того, чтобы устанавливать его в качестве фона, поместить его в изображение. –
Я не могу использовать представление изображения, как вы можете видеть в относительной компоновке. Я использую стрелку, камеру, имя пользователя и его статус. Я вынужден к изображению в фоновом режиме. Вы можете угадать сложность прилагаемого скриншота. –
вы можете установить их с помощью relativelayout –