I'm making an app in Android Studio, my problem is the position on the button. In the layout the position is correct, but in the simulator the button is in the left corner.
Example:
My code:
<androidx.appcompat.widget.AppCompatButton
android:id="@ id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#F10000"
android:onClick="onClick"
android:text="INICIO"
android:textColor="#000000"
tools:layout_editor_absoluteX="161dp"
tools:layout_editor_absoluteY="622dp />
CodePudding user response:
the tools
keyword in your Button is just to show in layout and nothing more, for define the position of the button you should rely on your button parent,for example if its LinearLayout
you can change the position of button by giving it android:layout_gravity
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@ id/parent">
<androidx.appcompat.widget.AppCompatButton
android:id="@ id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#F10000"
android:onClick="onClick"
android:text="INICIO"
android:textColor="#000000"
android:layout_gravity="center" />
</LinearLayout>