logo
down
shadow

ConstraintLayout not changing to landscape


ConstraintLayout not changing to landscape

By : user3042270
Date : November 27 2020, 05:23 PM
around this issue You can just make individual layout for landscape view. That way:
https://i.stack.imgur.com/4Adij.png
code :


Share : facebook icon twitter icon
Changing from landscape right directly to landscape left

Changing from landscape right directly to landscape left


By : Himanshu Jr
Date : March 29 2020, 07:55 AM
hope this fix your issue The problem here was with my handling of the orientation change, i should have from the beginning used :
code :
 if(UIInterfaceOrientationIsPortrait(self.interfaceOrientation))
cancellation of the content of the EditText when changing from PORTRAIT to Landscape and landscape to portrait

cancellation of the content of the EditText when changing from PORTRAIT to Landscape and landscape to portrait


By : illyasviel
Date : March 29 2020, 07:55 AM
Does that help Everytime orientation change, android create new view and destroy the old one. You can save your data when orientation change and re-initialize when the new view is created
Use onConfigurationChanged method of activity to detect Orientation Change
code :
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

    // Checks the orientation of the screen
    if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
        Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
    } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
        Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
    }
  }
<activity android:name=".MyActivity"
          android:configChanges="orientation|keyboardHidden"
          android:label="@string/app_name">
Dynamically changing the constraint of a view in ConstraintLayout

Dynamically changing the constraint of a view in ConstraintLayout


By : Shikher Goel
Date : March 29 2020, 07:55 AM
around this issue SOLUTION:
I managed to solve my issue with the following lines of code, it might help someone else if they face a similar problem.
code :
ConstraintSet set = new ConstraintSet();
set.clone(mConstraintLayout);
set.connect(mProgressBar.getId(), ConstraintSet.LEFT, R.id.guideline_category_left, ConstraintSet.LEFT, 0);
set.connect(mProgressBar.getId(), ConstraintSet.RIGHT, ConstraintSet.PARENT_ID, ConstraintSet.RIGHT, 0);
set.applyTo(mConstraintLayout);
Center align ImageButton in landscape mode using ConstraintLayout

Center align ImageButton in landscape mode using ConstraintLayout


By : user2845083
Date : March 29 2020, 07:55 AM
around this issue After I understood that the ScrollView is the element that's causing me headaches (thanks again, @glucaio!) I found this answer and was able to solve my problem.
The ScrollView received android:fitsSystemWindows="true", the inner ConstraintLayout had its attributes for width and height switched (android:layout_width="wrap_content" and android:layout_height="match_parent"), received a paddingTop and paddingBottom (instead of paddingStart and paddingEnd) and was wrapped in a LinearLayout:
code :
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:gravity="center" />
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:titleTextAppearance="@style/Toolbar.TitleText"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"/>

        <ScrollView
            android:id="@+id/fragment_container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="?attr/actionBarSize"
            android:fillViewport="true"
            app:layout_constraintTop_toBottomOf="@id/toolbar"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintBottom_toBottomOf="parent">

            <!-- Content of fragment_main.xml -->
            <LinearLayout
                xmlns:tools="http://schemas.android.com/tools"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:gravity="center"
                tools:context=".MainFragment">

                <androidx.constraintlayout.widget.ConstraintLayout
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_gravity="center"
                    android:paddingTop="30dp"
                    android:paddingBottom="30dp">


                    <ImageButton
                        android:id="@+id/overlay_button"
                        android:layout_width="0dp"
                        android:layout_height="0dp"
                        android:background="@null"
                        android:contentDescription="@string/start_speedometer"
                        android:scaleType="fitCenter"
                        android:src="@drawable/btn_circle_green"
                        app:layout_constraintDimensionRatio="1:1"
                        app:layout_constraintTop_toTopOf="parent"
                        app:layout_constraintBottom_toBottomOf="parent"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintEnd_toEndOf="parent"/>

                    <TextView
                        android:id="@+id/overlay_button_text"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:clickable="false"
                        android:text="@string/start_speedometer"
                        android:textColor="@color/white"
                        android:textSize="40sp"
                        app:layout_constraintTop_toTopOf="parent"
                        app:layout_constraintBottom_toBottomOf="parent"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintEnd_toEndOf="parent"/>

                </androidx.constraintlayout.widget.ConstraintLayout>

            </LinearLayout>

        </ScrollView>

    </androidx.constraintlayout.widget.ConstraintLayout>

    <com.google.android.material.navigation.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="false"
        app:menu="@menu/nav_drawer_view"
        app:headerLayout="@layout/nav_drawer_header"
        app:itemIconTint="@drawable/nav_drawer_item_icon_color"
        app:itemTextColor="@drawable/nav_drawer_item_text_color" />

</androidx.drawerlayout.widget.DrawerLayout>
ConstraintLayout that should support portrait and landscape modes -with a button to toggle full screen

ConstraintLayout that should support portrait and landscape modes -with a button to toggle full screen


By : Arioko
Date : March 29 2020, 07:55 AM
around this issue This can be done fairly simply using XML layouts for both portrait and landscape orientation and using weights to define the relative sizes of the views. When the toggle button is pressed, you make the blue/green views VISIBLE or GONE depending on the full screen state. The red view then resizes to fill the space vacated by the blue/green views.
Note the use of onSaveInstanceState to preserve the full screen state over configuration changes.
code :
package com.example.test;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {

    private boolean mFullScreen = false;
    private ImageView mBlue;

    private ImageView mGreen;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ImageButton toggleButton = findViewById(R.id.toggle_button);
        mBlue = findViewById(R.id.blue);
        mGreen = findViewById(R.id.green);
        if (savedInstanceState != null) {
            setFullScreen(savedInstanceState.getBoolean("mFullScreen", false));
        }
        toggleButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                setFullScreen(!mFullScreen);
            }
        });
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putBoolean("mFullScreen", mFullScreen);
    }

    private void setFullScreen(boolean fullScreen) {
        mFullScreen = fullScreen;
        mBlue.setVisibility(mFullScreen ? View.GONE : View.VISIBLE);
        mGreen.setVisibility(mFullScreen ? View.GONE : View.VISIBLE);
    }
}
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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=".MainActivity">

    <ImageView
        android:id="@+id/red"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="#ffff0000"
        app:layout_constraintBottom_toTopOf="@+id/blue"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_weight="0.7" />

    <ImageView
        android:id="@+id/blue"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="#ff0000ff"
        app:layout_constraintBottom_toTopOf="@+id/green"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/red"
        app:layout_constraintVertical_weight="0.2" />

    <ImageView
        android:id="@+id/green"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="#ff00ff00"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/blue"
        app:layout_constraintVertical_weight="0.1" />

    <ImageButton
        android:id="@+id/toggle_button"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_margin="15dp"
        android:background="#ffffa000"
        app:layout_constraintBottom_toBottomOf="@id/red"
        app:layout_constraintEnd_toEndOf="@id/red"/>

</android.support.constraint.ConstraintLayout>
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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=".MainActivity">

    <ImageView
        android:id="@+id/red"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:background="#ffff0000"
        app:layout_constraintBottom_toTopOf="@+id/green"
        app:layout_constraintEnd_toStartOf="@+id/blue"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_weight="0.9"
        app:layout_constraintHorizontal_weight="0.8"/>

    <ImageView
        android:id="@+id/blue"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:background="#ff0000ff"
        app:layout_constraintBottom_toTopOf="@+id/green"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toEndOf="@+id/red"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_weight="0.9"
        app:layout_constraintHorizontal_weight="0.2"/>

    <ImageView
        android:id="@+id/green"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="#ff00ff00"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/red"
        app:layout_constraintVertical_weight="0.1" />

    <ImageButton
        android:id="@+id/toggle_button"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_margin="15dp"
        android:background="#ffffa000"
        app:layout_constraintBottom_toBottomOf="@id/red"
        app:layout_constraintEnd_toEndOf="@id/red"/>

</android.support.constraint.ConstraintLayout>
Related Posts Related Posts :
  • List<String>- Null
  • How to normalize channel values to the range[0.0,1.0]?
  • How to convert a signed APK to an unsigned APK
  • Android library AAR packing resource incorrectly
  • Why it fail to upload apk to google play console?
  • How do I get more than 500 contact lists on Android?
  • Android layer-list affecting position of floating action button
  • Koin: NoBeanDefFoundException, Check your module definitions
  • Jetpack Navigation: Hide label in toolbar
  • get thumbnail from video URL but it takes more than 5 seconds to load data on recycler view
  • How to fix 'Android SDK not found at this location' error while installing flutter?
  • Android Shared Storage protection issue
  • How can I clone views using java code in Android Studio
  • Hide title and action bar for splash screen and remove White screen in start
  • Why can not hashing key android for facebook
  • Can not create handler inside thread that has not called Looper.prepare()
  • ID of the child views in a custom view are same in Android
  • Android: unable to hide appbar on scrolling
  • Best layout for form-style screen
  • How To create multiple function in Adapter Class Android with Retrofit
  • Can the Android Flow virtual layout handle variable-width Views
  • How to fix "Unable to load class 'dagger.Multibindings'" due to problems with gradle
  • VpnService always-on "not supported by this app"
  • Android Studio - Gradle "Sync now" is not Available
  • How do i get my code to give my current location?
  • Could not initialize class sun.util.calendar.ZoneInfoFile while using Flutter firebase-notifications
  • How to implement circular to check / tick animation in Android?
  • Toolbar shadow not showing
  • Android Sqlite get rows where first character is not an Alphabet
  • why I receive "bad request" in my request by retrofit
  • Intercept NavigationUI.onNavDestinationSelected() to make backstack pop with "inclusive = true"
  • I have a problem with the navigation fragments in my proyect, it sais that I need a defaut nav host atribute but I alrea
  • How can I keep a BottomSheetDialogFragment height to always match_parent?
  • How to reference a timerPicker in android studio using kotlin
  • Firebase Crashlytics - get stacktrace info to display during CrashlyticsListener.crashlyticsDidDetectCrashDuringPrevious
  • Schedule a repeating alarm clock
  • Can't assign values outside onTouchListener
  • Is setContentView() needed to inflate a fragment?
  • Why instead of string method returns Kotlin.Unit?
  • Retrofit slash as Query
  • When does onCreateView() get called in this app?
  • Fragment is reloaded each time after rejecting location permission
  • How to read ViewModel data from sttrings.xml list of items
  • Flutter doctor does not see vs code ,VS code does not detect flutter/bin
  • How to build aar in flutter
  • Gradle Build Fails - Illegal exception table range in class file com/google/wireless/android/sdk/stats/GradleBuildMemory
  • register has type Long (High Half) but expected Long (Low Half)
  • Is it good idea to use Dispatcher.Main with delay( )?
  • WebView and Advanced View is Not loading partiucalr URL
  • How to show three dots at the end of text view
  • Is it possible to run macros within Android Studio project?
  • Adding a button with default appearance but changed background color
  • What is best way to show notification at a certain time in Android?
  • Jetifier not working when library uses android component and app uses androidx component
  • How can I write the contents of an image in a filesystem
  • Retrieve a list of images from the Database and display them using a ListView?
  • java.lang.SecurityException: my location requires permission ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION
  • Timer/hourglass wont stop
  • How can I make AndroidX the default library for new Android projects?
  • Is it okay to delete buildToolsVersion android studio because of a warning in the Asyncstorage library?
  • shadow
    Privacy Policy - Terms - Contact Us © festivalmusicasacra.org