Adjust layout weights when resizing QR code view.

This commit is contained in:
akwizgran
2018-03-20 15:22:58 +00:00
parent 2c4d5680a6
commit 0d5d1f4cb2
3 changed files with 18 additions and 9 deletions

View File

@@ -14,6 +14,7 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.animation.AlphaAnimation; import android.view.animation.AlphaAnimation;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams; import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
@@ -54,6 +55,7 @@ import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
import static android.view.View.INVISIBLE; import static android.view.View.INVISIBLE;
import static android.view.View.VISIBLE; import static android.view.View.VISIBLE;
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
import static android.widget.LinearLayout.HORIZONTAL;
import static android.widget.Toast.LENGTH_LONG; import static android.widget.Toast.LENGTH_LONG;
import static java.util.logging.Level.INFO; import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING; import static java.util.logging.Level.WARNING;
@@ -133,20 +135,29 @@ public class ShowQrCodeFragment extends BaseEventFragment
ImageView fullscreenButton = view.findViewById(R.id.fullscreen_button); ImageView fullscreenButton = view.findViewById(R.id.fullscreen_button);
fullscreenButton.setOnClickListener(v -> { fullscreenButton.setOnClickListener(v -> {
View qrCodeContainer = view.findViewById(R.id.qr_code_container); View qrCodeContainer = view.findViewById(R.id.qr_code_container);
LinearLayout cameraOverlay = view.findViewById(R.id.camera_overlay);
LayoutParams statusParams, qrCodeParams;
if (fullscreen) { if (fullscreen) {
// Shrink the QR code container // Shrink the QR code container to fill half its parent
qrCodeContainer.setLayoutParams( if (cameraOverlay.getOrientation() == HORIZONTAL) {
new LayoutParams(MATCH_PARENT, 0, 1f)); statusParams = new LayoutParams(0, MATCH_PARENT, 1f);
qrCodeParams = new LayoutParams(0, MATCH_PARENT, 1f);
} else {
statusParams = new LayoutParams(MATCH_PARENT, 0, 1f);
qrCodeParams = new LayoutParams(MATCH_PARENT, 0, 1f);
}
fullscreenButton.setBackgroundResource( fullscreenButton.setBackgroundResource(
R.drawable.ic_fullscreen_black_48dp); R.drawable.ic_fullscreen_black_48dp);
} else { } else {
// Grow the QR code container // Grow the QR code container to fill its parent
qrCodeContainer.setLayoutParams( statusParams = new LayoutParams(0, 0, 0f);
new LayoutParams(MATCH_PARENT, MATCH_PARENT, 1f)); qrCodeParams = new LayoutParams(MATCH_PARENT, MATCH_PARENT, 1f);
fullscreenButton.setBackgroundResource( fullscreenButton.setBackgroundResource(
R.drawable.ic_fullscreen_exit_black_48dp); R.drawable.ic_fullscreen_exit_black_48dp);
} }
view.findViewById(R.id.camera_overlay).invalidate(); statusView.setLayoutParams(statusParams);
qrCodeContainer.setLayoutParams(qrCodeParams);
cameraOverlay.invalidate();
fullscreen = !fullscreen; fullscreen = !fullscreen;
}); });
} }

View File

@@ -15,7 +15,6 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="horizontal" android:orientation="horizontal"
android:weightSum="2"
android:baselineAligned="false"> android:baselineAligned="false">
<LinearLayout <LinearLayout

View File

@@ -15,7 +15,6 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical" android:orientation="vertical"
android:weightSum="2"
android:baselineAligned="false"> android:baselineAligned="false">
<LinearLayout <LinearLayout