From ee7d443c36d04c4e747722b5909c1e81a7373901 Mon Sep 17 00:00:00 2001 From: afnanramadhan <13521011@std.stei.itb.ac.id> Date: Thu, 4 Apr 2024 17:36:04 +0700 Subject: [PATCH] feat: fix image view scale twibbon --- .../example/android_hit/FragmentTwibbon.kt | 19 +++--- .../main/res/drawable/baseline_refresh_24.xml | 5 ++ .../res/layout/fragment_header_twibbon.xml | 2 +- app/src/main/res/layout/fragment_twibbon.xml | 66 ++++++++++++------- 4 files changed, 55 insertions(+), 37 deletions(-) create mode 100644 app/src/main/res/drawable/baseline_refresh_24.xml diff --git a/app/src/main/java/com/example/android_hit/FragmentTwibbon.kt b/app/src/main/java/com/example/android_hit/FragmentTwibbon.kt index b4ecc8b..57272af 100644 --- a/app/src/main/java/com/example/android_hit/FragmentTwibbon.kt +++ b/app/src/main/java/com/example/android_hit/FragmentTwibbon.kt @@ -121,17 +121,14 @@ class FragmentTwibbon : Fragment() { } private fun displayCapturedImage(bitmap: Bitmap?) { - bitmap?.let { - binding.imageView.setImageBitmap(it) - binding.imageView.scaleType = ImageView.ScaleType.FIT_XY - binding.imageView.layoutParams.width = it.width - binding.imageView.layoutParams.height = it.height - // Show/hide appropriate views - binding.retakeButton.visibility = View.VISIBLE - binding.previewView.visibility = View.GONE - binding.capture.visibility = View.GONE - binding.imageView.visibility = View.VISIBLE - } + binding.imageView.setImageBitmap(bitmap) + binding.imageView.scaleType = ImageView.ScaleType.CENTER_CROP + + // Show/hide appropriate views + binding.retakeButton.visibility = View.VISIBLE + binding.previewView.visibility = View.GONE + binding.capture.visibility = View.GONE + binding.imageView.visibility = View.VISIBLE } fun rotateBitmap(bitmap: Bitmap): Bitmap { diff --git a/app/src/main/res/drawable/baseline_refresh_24.xml b/app/src/main/res/drawable/baseline_refresh_24.xml new file mode 100644 index 0000000..7029604 --- /dev/null +++ b/app/src/main/res/drawable/baseline_refresh_24.xml @@ -0,0 +1,5 @@ +<vector android:height="24dp" android:tint="#322F50" + android:viewportHeight="24" android:viewportWidth="24" + android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> + <path android:fillColor="@android:color/white" android:pathData="M17.65,6.35C16.2,4.9 14.21,4 12,4c-4.42,0 -7.99,3.58 -7.99,8s3.57,8 7.99,8c3.73,0 6.84,-2.55 7.73,-6h-2.08c-0.82,2.33 -3.04,4 -5.65,4 -3.31,0 -6,-2.69 -6,-6s2.69,-6 6,-6c1.66,0 3.14,0.69 4.22,1.78L13,11h7V4l-2.35,2.35z"/> +</vector> diff --git a/app/src/main/res/layout/fragment_header_twibbon.xml b/app/src/main/res/layout/fragment_header_twibbon.xml index 218f994..17a88a3 100644 --- a/app/src/main/res/layout/fragment_header_twibbon.xml +++ b/app/src/main/res/layout/fragment_header_twibbon.xml @@ -33,7 +33,7 @@ android:id="@+id/imageView" android:layout_width="wrap_content" android:layout_height="match_parent" - android:src="@drawable/baseline_assignment_24" /> + android:src="@drawable/baseline_photo_camera_24" /> <TextView android:id="@+id/textView" diff --git a/app/src/main/res/layout/fragment_twibbon.xml b/app/src/main/res/layout/fragment_twibbon.xml index 96ee156..2dd0881 100644 --- a/app/src/main/res/layout/fragment_twibbon.xml +++ b/app/src/main/res/layout/fragment_twibbon.xml @@ -1,49 +1,65 @@ <?xml version="1.0" encoding="utf-8"?> -<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" +<androidx.constraintlayout.widget.ConstraintLayout 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" tools:context=".FragmentTwibbon"> - - <androidx.camera.view.PreviewView + <FrameLayout + android:id="@+id/frameLayout" android:layout_width="match_parent" - android:layout_height="550dp" - android:id="@+id/previewView" - /> + android:layout_height="500dp" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent"> + + <androidx.camera.view.PreviewView + android:id="@+id/previewView" + android:layout_width="match_parent" + android:layout_height="match_parent" /> + + <ImageView + android:id="@+id/imageView" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:scaleType="centerCrop" + android:visibility="gone" /> + + <ImageView + android:layout_width="match_parent" + android:layout_height="match_parent" + android:src="@drawable/twibbon" /> + </FrameLayout> <ImageButton + android:id="@+id/capture" android:layout_width="60sp" android:layout_height="60sp" - android:layout_centerHorizontal="true" android:layout_alignParentBottom="true" - android:layout_marginBottom="40sp" - android:id="@+id/capture" - android:src="@drawable/rounded_button" + android:layout_centerHorizontal="true" + android:background="?attr/selectableItemBackgroundBorderless" android:scaleType="centerCrop" - android:background="?attr/selectableItemBackgroundBorderless" /> - + android:src="@drawable/rounded_button" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/frameLayout" /> - <ImageView - android:id="@+id/imageView" - android:layout_width="match_parent" - android:layout_height="550dp" - android:visibility="gone"/> <ImageButton android:id="@+id/retakeButton" android:layout_width="60sp" android:layout_height="60sp" android:layout_alignParentBottom="true" - android:layout_marginBottom="41dp" - android:src="@drawable/iv_network_check" + android:background="?attr/selectableItemBackgroundBorderless" + android:src="@drawable/baseline_refresh_24" android:visibility="gone" - android:background="?attr/selectableItemBackgroundBorderless" /> + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toStartOf="@id/capture" + app:layout_constraintTop_toBottomOf="@+id/frameLayout" + app:layout_constraintStart_toStartOf="parent"/> - <ImageView - android:layout_width="match_parent" - android:layout_height="550dp" - android:src="@drawable/twibbon"/> -</RelativeLayout> \ No newline at end of file +</androidx.constraintlayout.widget.ConstraintLayout> \ No newline at end of file -- GitLab