QNA > H > How To Adjust A Layout In Portrait And Landscape Mode

How to adjust a layout in Portrait and Landscape mode

In this code:

  1. android:layout_width="match_parent" 
  2. android:layout_height="match_parent" 
  3. app:layout_constraintBottom_toBottomOf="parent" 
  4. app:layout_constraintLeft_toLeftOf="parent" 
  5. app:layout_constraintRight_toRightOf="parent" 
  6. app:layout_constraintTop_toTopOf="parent">  
  7.  
  8. android:id="@+id/tv1" 
  9. android:layout_width="300dp" 
  10. android:layout_height="wrap_content" 
  11. android:layout_centerHorizontal="true" 
  12. android:layout_marginTop="200dp" //remove 
  13. android:layout_weight="0" 
  14. android:hint="USERNAME" 
  15. android:textAlignment="center" 
  16.  
  17. /> 

In edit text just remove:

  1. android:layout_marginTop="200dp" 

and then in relative layout add these line of codes:

  1. android:layout_height="wrap_content" 
  2. app:layout_constraintHorizontal_bias="0.5" 
  3. app:layout_constraintVertical_bias="0.5" 

totally, code after modification:

  1. android:layout_width="wrap_content"  
  2. android:layout_height="wrap_content" 
  3. app:layout_constraintBottom_toBottomOf="parent"  
  4. app:layout_constraintBottom_toBottomOf="parent"  
  5. app:layout_constraintLeft_toLeftOf="parent"  
  6. app:layout_constraintRight_toRightOf="parent"  
  7. app:layout_constraintTop_toTopOf="parent" 
  8. app:layout_constraintHorizontal_bias="0.5"  
  9. app:layout_constraintVertical_bias="0.5" >  
  10.  
  11. android:id="@+id/tv1"  
  12. android:layout_width="300dp"  
  13. android:layout_height="wrap_content"  
  14. android:layout_centerHorizontal="true"  
  15. android:layout_weight="0"  
  16. android:hint="USERNAME"  
  17. android:textAlignment="center"  
  18. /> 

So,now it will perfectly align in landscape mode also, like this:

main-qimg-5ac75b410dcc7aee59c6e152d8614dc4

Hope it helpes.

Di Agustin Eikleberry

Come dire quale filo è positivo in un cavo micro USB :: Qual è la differenza tra i connettori USB micro-A e micro-B?
Link utili