외부보기 2 개가 고정 너비이고 가운데보기가 나머지 사용 가능한 가로 공간을 채우도록 3 개의보기를 가로로 배치하는 방법은 무엇입니까? 이 작업을 수행하려는 모든 시도로 인해 가장 오른쪽의보기가 화면 밖으로 밀려났습니다.Android 레이아웃 : 두 개의 고정 너비보기 사이의 가변 너비보기
0
A
답변
0
나는이 작업을하기 위해 잠시 고생했으며 RelativeLayout
으로 어떻게해야하는지 발견했습니다. 아래의 코드 예제를 참조 layout_toRightOf
, layout_toLeftOf
의 사용에주의를 지불하고 layout_alignParentRight
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="@dimen/eventDetailSectionHeight"
android:background="@color/grayout">
<SomeFixedWidthView
android:id="@+id/leftFixedWidthView"
android:layout_width="100dp"
android:layout_height="match_parent"/>
<SomeVariableWidthView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toRightOf="@id/leftFixedWidthView"
android:layout_toLeftOf="@+id/rightFixedWidthView"/>
<SomeFixedWidthView
android:id="@+id/rightFixedWidthView"
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_alignParentRight="true"/>
</RelativeLayout>
0
는 요구 사항에 따라 각 자녀에 대한 layout_weight를 설정하십시오. 원하는 결과에 대한 코드 아래
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<View
android:id="@+id/leftView"
android:layout_width="0dp"
android:layout_weight="0.4"
android:layout_height="match_parent"
android:background="#ff0000"/>
<View
android:id="@+id/middleView"
android:layout_width="0dp"
android:layout_weight="0.2"
android:layout_height="match_parent"
android:background="#33cc33"/>
<View
android:id="@+id/rightView"
android:layout_width="0dp"
android:layout_weight="0.4"
android:layout_height="match_parent"
android:background="#ff0000"/>/>
</LinearLayout>
0
사용
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:id="@+id/leftView"
android:layout_width="100dp"
android:layout_height="match_parent"
android:background="#ff0000"/>
<View
android:id="@+id/middleView"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#33cc33"/>
<View
android:id="@+id/rightView"
android:layout_width="100dp"
android:layout_height="match_parent"
android:background="#ff0000"/>
</LinearLayout>