질문 업데이트 : LinearLayout이 훨씬 뛰어 났으며 이미 선형으로 구현되었습니다. RelativeLaouyt 구현이 필요한 교육적 과제가 있습니다. 선형 레이아웃에 대해 언급하지 마십시오. 제 질문의 목적이 아닙니다.android RelativeLayout에서 3 개의 버튼에 대해 동일한 너비를 설정하는 방법은 무엇입니까?
저는 LinearLayout에서 훨씬 더 쉽지만, RelativeLayout으로 구현해야한다는 것을 알고 있습니다. xml 파일에 3 개의 버튼이 있고 같은 줄에 있고 화면의 1/3과 동일한 너비가 있어야합니다.
는 (I는 "가짜"보기를 사용하여이 개 버튼에 대한 here 멋진 해결책을 발견했다.하지만 3 개 버튼이 작동하지 않습니다.)어떤 아이디어가? (상대 레이아웃에만 해당)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_margin="10dp">
<Button
android:id="@+id/bottom_left"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="Left"/>
<Button
android:id="@+id/bottom_center"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_centerInParent="true"
android:text="Center"/>
<Button
android:id="@+id/bottom_right"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_alignParentRight="true"
android:text="Right"/>
</RelativeLayout>
언제든지 프로그래밍 방식으로 추가하고 거기에서 너비를 계산할 수 있습니다. –
선형 레이아웃보다 상대적입니다. 선형을 수행 한 다음 각 버튼에 균등 한 가중치를 부여 할 수 있습니다. – Phil3992
** 'LinearLayout'을 사용하지 않는 이유는 무엇입니까? 각 레이아웃은 용도로만 사용됩니다. 용도에 맞게 레이아웃을 사용하지 않으면 UI가 전혀 최적화되지 않습니다. –