I cannot seem to find the right keywords for my question. Not to be confused with XML Layout editing, can I programmatically shift one View
under another View
in real-time inside a LinearLayout
container?
Here is my main layout XML file. It is as easy as just dragging the two buttons to the UI editor and naming them:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:background="#000000"
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button 1" />
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button 2" />
</LinearLayout>
Let's say I did something in my app and suddenly button1
shifted below button2
and button2
went up. How can I make that happen? Does something like my1Button.shiftDown();
or similar even exist?