How to adjust a layout in Portrait and Landscape mode
In this code:
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- app:layout_constraintBottom_toBottomOf="parent"
- app:layout_constraintLeft_toLeftOf="parent"
- app:layout_constraintRight_toRightOf="parent"
- app:layout_constraintTop_toTopOf="parent">
- android:id="@+id/tv1"
- android:layout_width="300dp"
- android:layout_height="wrap_content"
- android:layout_centerHorizontal="true"
- android:layout_marginTop="200dp" //remove
- android:layout_weight="0"
- android:hint="USERNAME"
- android:textAlignment="center"
- />
In edit text just remove:
- android:layout_marginTop="200dp"
and then in relative layout add these line of codes:
- android:layout_height="wrap_content"
- app:layout_constraintHorizontal_bias="0.5"
- app:layout_constraintVertical_bias="0.5"
totally, code after modification:
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- app:layout_constraintBottom_toBottomOf="parent"
- app:layout_constraintBottom_toBottomOf="parent"
- app:layout_constraintLeft_toLeftOf="parent"
- app:layout_constraintRight_toRightOf="parent"
- app:layout_constraintTop_toTopOf="parent"
- app:layout_constraintHorizontal_bias="0.5"
- app:layout_constraintVertical_bias="0.5" >
- android:id="@+id/tv1"
- android:layout_width="300dp"
- android:layout_height="wrap_content"
- android:layout_centerHorizontal="true"
- android:layout_weight="0"
- android:hint="USERNAME"
- android:textAlignment="center"
- />
So,now it will perfectly align in landscape mode also, like this:
Hope it helpes.
Articoli simili
- Cosa è meglio progettare, un layout relativo o un layout lineare in Android?
- What is a reliable VoIP provider that offers UK and German numbers, inbound + outbound and also has Android and iPhone apps?
- How to make my Android app play sound even in Do Not Disturb Mode
- Qual è la differenza tra wind down, dark mode, filtro luce blu e do not disturb?