hmahdavi
hmahdavi

Reputation: 2354

Why change the image of imageview on different mobile devices , have different results?

I want in my project with the push of a button imageview image change. Pictures taken by the camera and stored in sdcard.The result is different in different mobiles. In some mobiles like Samsung s4 phone is displayed correctly. Imageview fills the screen. But, in some mobiles that have low-resolution screen Smaller displays.

To do change imageview image, I use this method. Please advice.

private void change_image_of_imageView() {
    File file = new File(Environment.getExternalStorageDirectory().getPath() + "/nabege" + File.separator + "images"
            + File.separator + imageFileName);
    try {
        if (file.exists()) {
            Bitmap bmp1 = BitmapFactory.decodeFile(file.getAbsolutePath());
            Matrix matrix = new Matrix();
            float angle = 90;
            matrix.postRotate(angle);
            Bitmap bmp2 = Bitmap.createBitmap(bmp1, 0, 0, bmp1.getWidth(), bmp1.getHeight(), matrix, true);
            Bitmap bmp3 = Bitmap.createScaledBitmap(bmp2, bmp2.getWidth(), bmp2.getHeight(), true);
            btn_showImage.setImageBitmap(bmp3);
        }
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}


<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <Button
            android:id="@+id/btn_pre"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_margin="3dp"
            android:layout_weight="1"
            android:background="@drawable/button_success"
            android:shadowColor="#592B2B"
            android:shadowDx="9"
            android:shadowDy="0"
            android:shadowRadius="15"
            android:text="@string/pre"
            android:textColor="#fff"
            android:textSize="20sp" />

        <Button
            android:id="@+id/btn_next"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_margin="3dp"
            android:layout_weight="1"
            android:background="@drawable/button_success"
            android:shadowColor="#592B2B"
            android:shadowDx="9"
            android:shadowDy="0"
            android:shadowRadius="15"
            android:text="@string/next"
            android:textColor="#fff"
            android:textSize="20sp" />
    </LinearLayout>

    <RatingBar
        android:id="@+id/ratingBar1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:isIndicator="true"
        android:numStars="6" />

    <TextView
        android:id="@+id/txt_name_subject"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal" />

    <TextView
        android:id="@+id/txt_text_subject"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

    <ImageView
        android:id="@+id/iv_sound"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal" />

    <SeekBar
        android:id="@+id/seekBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <ImageView
        android:id="@+id/iv_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal" />

    <ImageView
        android:id="@+id/iv_video"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal" />
</LinearLayout>

Upvotes: 0

Views: 94

Answers (2)

hmahdavi
hmahdavi

Reputation: 2354

One reason for this problem take pictures in landscape mode and portrait mode. If you ever take photos in landscape mode this problem is solved. But created the empty space between imageview and the top of it.

enter image description here

Upvotes: 0

gesuwall
gesuwall

Reputation: 607

The error is more likely to be in your layout. What ScaleType are you using for the ImageView?

You might want to read this article about ScaleType in android to get your desired results.

http://www.techrepublic.com/article/clear-up-ambiguity-about-android-image-view-scale-types-with-this-guide/

Upvotes: 1

Related Questions