Readdy Write

Android: Constraint Layout zu RelativeLayout ändern

28.12.2020 (👁3727)

Android: Layout RelativeLayout

 

Anleitung einfache Anpassung eines Android Layouts

Zunächst ändert man die Standard Activity Layout von Constraints zu RelativeLayout

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   
xmlns:app="http://schemas.android.com/apk/res-auto"

Dann fügt man ein zentral orientiertes Element ein, indem man in diesem Element die layout_centerInParent auf true setzt

android:layout_centerInParent="true"

Danach kann man folgende Elemente mit below anfügen

        android:layout_below="@id/txtViewStart"
       
android:layout_centerHorizontal="true"

 

 

 

Android xml code: activity_main.xml

 

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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">

    <
TextView
       
android:id="@+id/txtViewStart"
       
android:layout_width="wrap_content"
       
android:layout_height="wrap_content"
       
android:text="Positions"
       
android:layout_centerInParent="true" />

    <
Button
        
android:id="@+id/btnSetAlarm"
       
android:layout_width="wrap_content"
       
android:layout_height="wrap_content"
       
android:onClick="BtnAlarmOnClick"
       
android:text="Set Alarm"
       
android:layout_below="@id/txtViewStart"
       
android:layout_centerHorizontal="true"
        
/>
</
RelativeLayout>

 


0,00 €