Reputation: 83
Hi I am doing kotlin calculator app for university homework and i had buttons being placed like this
<Button
android:id="@+id/button_two"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@drawable/background_color"
android:gravity="center"
android:text="2"
android:textColor="@android:color/black"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_percent="0.12"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.832"
app:layout_constraintHorizontal_bias="0.35"
app:layout_constraintWidth_percent="0.22" />
Now my teacher told me that i have to use guidelines for this so i made one vertical and one horizontal but i have problems doing another buttons cause i want them to relate to the one near them so for example in code below:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".AdvancedCalcActivity">
<androidx.constraintlayout.widget.Guideline
android:id="@+id/horizontalGuideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@android:color/black"
app:layout_constraintGuide_percent="0.3" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/verticalGuideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.02" />
<Button
android:id="@+id/button_ac"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@drawable/background_color"
android:text="AC"
app:layout_constraintHeight_percent="0.12"
app:layout_constraintWidth_percent="0.22"
app:layout_constraintStart_toStartOf="@+id/verticalGuideline"
app:layout_constraintTop_toBottomOf="@+id/horizontalGuideline" />
</androidx.constraintlayout.widget.ConstraintLayout>
i want another button lets call it "+" to be realted to AC button not using DPI but using values like the first code i provided so it can be fully responsive on all devices and in horizontal and landscape mode
Upvotes: 0
Views: 62