Readdy Write  
0,00 €
Your View Money
Views: Count
Self 20% 0
Your Content 60% 0

Users by Links 0
u1*(Content+Views) 10% 0
Follow-Follower 0
s2*(Income) 5% 0

Count
Followers 0
Login Register as User

Android: Constraint Layout zu RelativeLayout ändern

28.12.2020 (👁202)

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>