<?xml version="1.0" encoding="utf-8"?> <AbsoluteLayout 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" android:background="@drawable/asdasd" android:orientation="vertical" > <!-- --> <Button android:id="@+id/buttonG7" android:layout_width="65dp" android:layout_height="35dp" android:text="asdasdasd" tools:layout_x="124dp" tools:layout_y="317dp" ></Button> <Button android:id="@+id/buttonF" android:layout_width="65dp" android:layout_height="35dp" tools:layout_x="10dp" tools:layout_y="144dp"></Button> <Button android:id="@+id/buttonC" android:layout_width="65dp" android:layout_height="35dp" tools:layout_x="10dp" tools:layout_y="180dp"></Button> <Button android:id="@+id/buttonGs" android:layout_width="65dp" android:layout_height="35dp" tools:layout_x="10dp" tools:layout_y="215dp"></Button> <Button android:id="@+id/buttonDs" android:layout_width="65dp" android:layout_height="35dp" tools:layout_x="10dp" tools:layout_y="250dp"></Button> <Button android:id="@+id/buttonAs" android:layout_width="65dp" android:layout_height="35dp" tools:layout_x="10dp" tools:layout_y="285dp"></Button> <Button android:id="@+id/buttonF6" android:layout_width="65dp" android:layout_height="35dp" tools:layout_x="10dp" tools:layout_y="315dp"></Button> <Button android:id="@+id/buttonG" android:layout_width="65dp" android:layout_height="35dp" tools:layout_x="124dp" tools:layout_y="144dp"></Button> <Button android:id="@+id/buttonD" android:layout_width="65dp" android:layout_height="35dp" tools:layout_x="124dp" tools:layout_y="179dp"></Button> <Button android:id="@+id/buttonF5" android:layout_width="65dp" android:layout_height="35dp" tools:layout_x="124dp" tools:layout_y="247dp"></Button> <Button android:id="@+id/buttonC5" android:layout_width="65dp" android:layout_height="35dp" tools:layout_x="124dp" tools:layout_y="282dp"></Button> <Button android:id="@+id/buttonAs5" android:layout_width="65dp" android:layout_height="35dp" tools:layout_x="124dp" tools:layout_y="212dp"></Button> <!----> <Button android:id="@+id/buttonA" android:layout_width="65dp" android:layout_height="35dp" tools:layout_x="236dp" tools:layout_y="144dp"></Button> <Button android:id="@+id/buttonE" android:layout_width="65dp" android:layout_height="35dp" tools:layout_x="236dp" tools:layout_y="179dp"></Button> <Button android:id="@+id/buttonC2" android:layout_width="65dp" android:layout_height="35dp" tools:layout_x="236dp" tools:layout_y="212dp"></Button> <Button android:id="@+id/buttonD2" android:layout_width="65dp" android:layout_height="35dp" tools:layout_x="236dp" tools:layout_y="282dp"></Button> <Button android:id="@+id/buttonA2" android:layout_width="65dp" android:layout_height="35dp" tools:layout_x="236dp" tools:layout_y="317dp"></Button> <Button android:id="@+id/buttonG2" android:layout_width="65dp" android:layout_height="35dp" tools:layout_x="236dp" tools:layout_y="247dp"></Button> <!-- --> <Button android:id="@+id/buttonB" android:layout_width="65dp" android:layout_height="35dp" tools:layout_x="351dp" tools:layout_y="144dp"></Button> <Button android:id="@+id/buttonD3" android:layout_width="65dp" android:layout_height="35dp" tools:layout_x="351dp" tools:layout_y="212dp"></Button> <Button android:id="@+id/buttonA3" android:layout_width="65dp" android:layout_height="35dp" tools:layout_x="351dp" tools:layout_y="247dp"></Button> <Button android:id="@+id/buttonE2" android:layout_width="65dp" android:layout_height="35dp" tools:layout_x="351dp" tools:layout_y="282dp"></Button> <Button android:id="@+id/buttonB2" android:layout_width="65dp" android:layout_height="35dp" tools:layout_x="351dp" tools:layout_y="317dp"></Button> <Button android:id="@+id/buttonFs" android:layout_width="65dp" android:layout_height="35dp" tools:layout_x="351dp" tools:layout_y="179dp"></Button> <!----> <Button android:id="@+id/buttonC3" android:layout_width="65dp" android:layout_height="35dp" tools:layout_x="471dp" tools:layout_y="144dp"></Button> <Button android:id="@+id/buttonG3" android:layout_width="65dp" android:layout_height="35dp" tools:layout_x="471dp" tools:layout_y="179dp"></Button> <Button android:id="@+id/buttonAs2" android:layout_width="65dp" android:layout_height="35dp" tools:layout_x="471dp" tools:layout_y="247dp"></Button> <Button android:id="@+id/buttonF2" android:layout_width="65dp" android:layout_height="35dp" tools:layout_x="471dp" tools:layout_y="282dp"></Button> <Button android:id="@+id/buttonC4" android:layout_width="65dp" android:layout_height="35dp" tools:layout_x="471dp" tools:layout_y="317dp"></Button> <Button android:id="@+id/buttonDs2" android:layout_width="65dp" android:layout_height="35dp" tools:layout_x="471dp" tools:layout_y="212dp"></Button> <!----> <Button android:id="@+id/buttonD4" android:layout_width="65dp" android:layout_height="35dp" tools:layout_x="604dp" tools:layout_y="144dp"></Button> <Button android:id="@+id/buttonF3" android:layout_width="65dp" android:layout_height="35dp" tools:layout_x="604dp" tools:layout_y="212dp"></Button> <Button android:id="@+id/buttonG4" android:layout_width="65dp" android:layout_height="35dp" tools:layout_x="604dp" tools:layout_y="282dp"></Button> <Button android:id="@+id/buttonD7" android:layout_width="65dp" android:layout_height="35dp" tools:layout_x="604dp" tools:layout_y="317dp"></Button> <Button android:id="@+id/buttonAs4" android:layout_width="65dp" android:layout_height="35dp" tools:layout_x="604dp" tools:layout_y="247dp"></Button> <Button android:id="@+id/buttonA4" android:layout_width="65dp" android:layout_height="35dp" tools:layout_x="604dp" tools:layout_y="179dp"></Button> <!----> <Button android:id="@+id/buttonD5" android:layout_width="65dp" android:layout_height="35dp" tools:layout_x="604dp" tools:layout_y="144dp"></Button> <Button android:id="@+id/buttonF4" android:layout_width="65dp" android:layout_height="35dp" tools:layout_x="604dp" tools:layout_y="212dp"></Button> <Button android:id="@+id/buttonG6" android:layout_width="65dp" android:layout_height="35dp" tools:layout_x="604dp" tools:layout_y="282dp"></Button> <Button android:id="@+id/buttonD8" android:layout_width="65dp" android:layout_height="35dp" tools:layout_x="604dp" tools:layout_y="317dp"></Button> <Button android:id="@+id/buttonAs3" android:layout_width="65dp" android:layout_height="35dp" tools:layout_x="604dp" tools:layout_y="247dp"></Button> <Button android:id="@+id/buttonA6" android:layout_width="65dp" android:layout_height="35dp" tools:layout_x="604dp" tools:layout_y="179dp"></Button> <!-- --> <Button android:id="@+id/buttonE3" android:layout_width="65dp" android:layout_height="35dp" tools:layout_x="713dp" tools:layout_y="144dp"></Button> <Button android:id="@+id/buttonB3" android:layout_width="65dp" android:layout_height="35dp" tools:layout_x="713dp" tools:layout_y="179dp"></Button> <Button android:id="@+id/buttonD6" android:layout_width="65dp" android:layout_height="35dp" tools:layout_x="713dp" tools:layout_y="247dp"></Button> <Button android:id="@+id/buttonA5" android:layout_width="65dp" android:layout_height="35dp" tools:layout_x="713dp" tools:layout_y="282dp"></Button> <Button android:id="@+id/buttonE4" android:layout_width="65dp" android:layout_height="35dp" tools:layout_x="713dp" tools:layout_y="317dp"></Button> <Button android:id="@+id/buttonG5" android:layout_width="65dp" android:layout_height="35dp" tools:layout_x="713dp" tools:layout_y="212dp"></Button> </AbsoluteLayout>
when i build this code,
app will open on landscape mode.
but all of my buttons are nesting
and it shows only 1 btn
how can i solve it?
i had tried by constraint view, but it was same.
this is my github
https://github.com/sksmsWKd/2021android-backup/commit/cb6bb1774b3f8307f211ed6feb16eab0a9bf3620
i pushed this code today
Advertisement
Answer
Try this:
<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent"> <androidx.constraintlayout.widget.ConstraintLayout android:id="@+id/constraintLayoutFirst" android:layout_width="wrap_content" android:layout_height="wrap_content" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintEnd_toStartOf="@id/constraintLayoutSecond"> <Button android:id="@+id/btn1" android:layout_width="wrap_content" android:layout_height="wrap_content" app:layout_constraintBottom_toTopOf="@id/btn2" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_chainStyle="packed" /> <Button android:id="@+id/btn2" android:layout_width="wrap_content" android:layout_height="wrap_content" app:layout_constraintBottom_toTopOf="@id/btn3" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/btn1" /> <Button android:id="@+id/btn3" android:layout_width="wrap_content" android:layout_height="wrap_content" app:layout_constraintBottom_toTopOf="@id/btn4" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/btn2" /> <Button android:id="@+id/btn4" android:layout_width="wrap_content" android:layout_height="wrap_content" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/btn3" /> </androidx.constraintlayout.widget.ConstraintLayout> <androidx.constraintlayout.widget.ConstraintLayout android:id="@+id/constraintLayoutSecond" android:layout_width="wrap_content" android:layout_height="wrap_content" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toEndOf="@id/constraintLayoutFirst" app:layout_constraintEnd_toStartOf="@id/constraintLayoutThirst" app:layout_constraintTop_toTopOf="parent"> <Button android:id="@+id/btn5" android:layout_width="wrap_content" android:layout_height="wrap_content" app:layout_constraintBottom_toTopOf="@id/btn6" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_chainStyle="packed" /> <Button android:id="@+id/btn6" android:layout_width="wrap_content" android:layout_height="wrap_content" app:layout_constraintBottom_toTopOf="@id/btn7" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/btn5" /> <Button android:id="@+id/btn7" android:layout_width="wrap_content" android:layout_height="wrap_content" app:layout_constraintBottom_toTopOf="@id/btn8" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/btn6" /> <Button android:id="@+id/btn8" android:layout_width="wrap_content" android:layout_height="wrap_content" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/btn7" /> </androidx.constraintlayout.widget.ConstraintLayout> <androidx.constraintlayout.widget.ConstraintLayout android:id="@+id/constraintLayoutThirst" android:layout_width="wrap_content" android:layout_height="wrap_content" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toEndOf="@id/constraintLayoutSecond" app:layout_constraintEnd_toStartOf="@id/constraintLayoutFour" app:layout_constraintTop_toTopOf="parent"> <Button android:id="@+id/btn9" android:layout_width="wrap_content" android:layout_height="wrap_content" app:layout_constraintBottom_toTopOf="@id/btn10" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_chainStyle="packed" /> <Button android:id="@+id/btn10" android:layout_width="wrap_content" android:layout_height="wrap_content" app:layout_constraintBottom_toTopOf="@id/btn11" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/btn9" /> <Button android:id="@+id/btn11" android:layout_width="wrap_content" android:layout_height="wrap_content" app:layout_constraintBottom_toTopOf="@id/btn12" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/btn10" /> <Button android:id="@+id/btn12" android:layout_width="wrap_content" android:layout_height="wrap_content" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/btn11" /> </androidx.constraintlayout.widget.ConstraintLayout> <androidx.constraintlayout.widget.ConstraintLayout android:id="@+id/constraintLayoutFour" android:layout_width="wrap_content" android:layout_height="wrap_content" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toEndOf="@id/constraintLayoutThirst" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="parent"> <Button android:id="@+id/btn13" android:layout_width="wrap_content" android:layout_height="wrap_content" app:layout_constraintBottom_toTopOf="@id/btn14" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_chainStyle="packed" /> <Button android:id="@+id/btn14" android:layout_width="wrap_content" android:layout_height="wrap_content" app:layout_constraintBottom_toTopOf="@id/btn13" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/btn15" /> <Button android:id="@+id/btn15" android:layout_width="wrap_content" android:layout_height="wrap_content" app:layout_constraintBottom_toTopOf="@id/btn16" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/btn14" /> <Button android:id="@+id/btn16" android:layout_width="wrap_content" android:layout_height="wrap_content" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/btn15" /> </androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
Set layout in landscape:
<activity android:name="YourActivity" android:screenOrientation="landscape"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>
AbsoluteLayout is deprecated, you should’t use this and if you want to move button you can use margin as:
<Button android:id="@+id/btn16" ... android:layout_marginTop="10dp" android:layout_marginStart="10dp"/>
instead of:
<Button android:id="@+id/btn16" ... tools:layout_x="10dp" tools:layout_y="10dp"/>