为什么在不同的移动设备上更改imageview的图像,会有不同的结果?

时间:2015-09-22 14:59:36

标签: android imageview

我希望在我的项目中按下按钮imageview图像更改。 相机拍摄的照片并存储在SD卡中。不同手机的结果不同。 在一些手机,如三星s4手机正确显示。 Imageview填满了屏幕。但是,在一些具有低分辨率屏幕较小显示器的手机中。

要更改imageview图像,我使用此方法。 请指教。

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>

2 个答案:

答案 0 :(得分:1)

错误更可能出现在您的布局中。您使用什么ScaleType用于ImageView?

您可能希望在Android中阅读有关ScaleType的文章,以获得所需的结果。

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

答案 1 :(得分:0)

此问题的一个原因是在横向模式和纵向模式下拍照。 如果您在横向模式下拍照,这个问题就解决了。但是在imageview和它顶部创建了空白区域。

enter image description here