我正在尝试将一个ImageView放置在屏幕中央,然后在它的上下方放置其他视图,因此我决定使用一个LinearLayout(垂直)和一个LinearLayout(水平)。但是,当我为ImageView使用layout_weight时,图像完全消失了(显示一个空白屏幕)。ImageView的图像是在onCreate()中设置的。我希望ImageView占据屏幕宽度的50%,因此我使用了权重。
<?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>