위와 아래에 다른 뷰를 놓을 목적으로 ImageView를 화면 중간에 배치하려고하므로 LinearLayout (세로) 및 LinearLayout (가로). 그러나 ImageView에 layout_weight를 사용하면 이미지가 완전히 사라집니다 (빈 화면이 표시됨). ImageView의 이미지는 onCreate()에 설정됩니다. ImageView가 화면의 너비의 50 %를 차지하고 싶습니다. 따라서 가중치를 사용합니다.LinearLayout에서 ImageView와 함께 layout_weight 사용
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" android:orientation="vertical">
<View
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"/>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="horizontal"
android:layout_weight="2">
<View android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"/>
<ImageView android:layout_weight="2" android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/albumArtImageView"></ImageView>
<View android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"/>
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"/>
</LinearLayout>
분명히 layout_height = "0"으로 설정할 때 정수형을 사용할 수 없습니다. – Alex
0dp가 작동합니다. 고마워, 테드. – Alex
Ack. 나는 항상 그 실수를 저지른다. 내 대답을 바로 잡아서 다른 누군가가 그걸로 넘어 가지 않게하려고합니다. –