Browse Source

1.修改RA Image Android照片列表图像显示变形。

Pen Li 8 years ago
parent
commit
5f0e5c683c

+ 33 - 24
RA Image/app/src/main/java/com/usai/redant/raimage/PhotoList/PhotoGridActivity.java

@@ -7,6 +7,7 @@ import android.graphics.BitmapFactory;
 import android.support.v7.app.ActionBar;
 import android.support.v7.app.AppCompatActivity;
 import android.os.Bundle;
+import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.MenuItem;
 import android.view.View;
@@ -88,7 +89,7 @@ public class PhotoGridActivity extends AppCompatActivity {
         }
         gridView.setNumColumns(col);
 
-
+        Log.d("List", "onCreate: setAdapter");
         // 设置Adapter
         gridView.setAdapter(adapter = new GridViewAdapter());
 
@@ -100,6 +101,12 @@ public class PhotoGridActivity extends AppCompatActivity {
         mActionBar.setTitle("RA Image");
     }
 
+    @Override
+    protected void onStart() {
+        super.onStart();
+        Log.d("List", "onStart");
+    }
+
     @Override
     public boolean onOptionsItemSelected(MenuItem item) {
         switch (item.getItemId()) {
@@ -128,30 +135,30 @@ public class PhotoGridActivity extends AppCompatActivity {
 
 
     /**缩小图片*/
-    public Bitmap scaleImage(String path,int width,int height) {
+    public Bitmap scaleImage(String path) {
         Bitmap source = BitmapFactory.decodeFile(path);
 
-//        int originWidth = source.getWidth();
-//        int originHeight = source.getHeight();
-//
-//        int width = originWidth, height = originHeight;
-//
-//        if (originHeight > 1024 || originWidth > 1024)
-//        {
-//            if (originWidth > originHeight)
-//            {
-//                width = 1024;
-//                height = originHeight * 1024 / originWidth;
-//
-//            }
-//            else
-//            {
-//
-//                height = 1024;
-//                width = originWidth * 1024 / originHeight;
-//
-//            }
-//        }
+        int originWidth = source.getWidth();
+        int originHeight = source.getHeight();
+
+        int width = originWidth, height = originHeight;
+
+        if (originHeight > 1024 || originWidth > 1024)
+        {
+            if (originWidth > originHeight)
+            {
+                width = 1024;
+                height = originHeight * 1024 / originWidth;
+
+            }
+            else
+            {
+
+                height = 1024;
+                width = originWidth * 1024 / originHeight;
+
+            }
+        }
         Bitmap scaled = Bitmap.createScaledBitmap(source, width, height, true);
         return scaled;
     }
@@ -206,7 +213,8 @@ public class PhotoGridActivity extends AppCompatActivity {
             String path = item.get("path");
 
 
-            Bitmap bitmap = scaleImage(path,500,500);
+            Bitmap bitmap = scaleImage(path);
+//            Bitmap bitmap = BitmapFactory.decodeFile(path);
 
             holder.photoView.setImageBitmap(bitmap);
 
@@ -259,6 +267,7 @@ public class PhotoGridActivity extends AppCompatActivity {
             }
             cell.setLayoutParams(param);
 
+            Log.d("List", "Return Cell");
             return cell;
         }
 

+ 1 - 1
RA Image/app/src/main/res/layout/photo_list_item.xml

@@ -9,8 +9,8 @@
         android:id="@+id/photo_list_iv"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
-        android:scaleType="centerCrop"
         android:layout_margin="0dp"
+        android:scaleType="centerCrop"
         />
 
     <ImageButton