일단기록/간단기록
[안드로이드/android] editText 위에 겹쳐진 버튼
겟츄
2022. 5. 18. 16:53
editText 위에 버튼을 올려서 구현하려면 다음과 같다.

<?xml version="1.0" encoding="utf-8"?>
<layout 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">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="20dp"
tools:ignore="MissingConstraints">
<GridLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal"
android:columnCount="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_column="0"
android:layout_row="0"
android:layout_gravity="center">
<EditText
android:layout_width="match_parent"
android:layout_height="46dp"
android:textSize="16sp"
android:layout_column="1"
android:hint="editText"/>
</LinearLayout>
<LinearLayout
android:layout_column="0"
android:layout_row="0"
android:layout_gravity="right"
android:layout_marginRight="2dp">
<Button
android:layout_width="70dp"
android:layout_height="40dp"
android:layout_column="1"
android:text="버튼1"
android:layout_gravity="right"
android:layout_marginRight="10dp"/>
<Button
android:layout_width="70dp"
android:layout_height="40dp"
android:text="버튼2"
android:layout_column="1"
android:layout_gravity="right"/>
</LinearLayout>
</GridLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
위와 같이 구성을 했을 경우 버튼 2의 visibility를 "gone"으로 설정해주면 아래와 같이 버튼 1이 오른쪽으로 붙는다.
