我正在嘗試使視圖完全覆蓋另一個視圖以「灰顯」。所以我用一個RelativeLayout添加了一個在它上面有一點透明顏色的視圖。但是,即使我使用「fill_parent」,頂部視圖佔據了0高度。例如,如果我更改爲TextView,它會佔用wrap_content的空間。我怎樣才能讓我的視圖覆蓋整個視圖(可能會有所不同)? 我真正的代碼:完全覆蓋另一個視圖的視圖
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/unit_entry"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingBottom="3dip">
<include layout="@layout/view_stats"
android:id="@+id/unit_stats"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="@id/unit_stats">
<LinearLayout
android:layout_weight="1"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:orientation="vertical">
<include layout="@layout/view_heading_value_text"
android:id="@+id/unit_exp_layout"/>
<TextView
android:id="@+id/unit_skills_text"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:hint="@string/skills_injuries_hint"
android:background="@drawable/border"/>
</LinearLayout>
<TextView
android:id="@+id/unit_equipment_text"
android:layout_weight="1"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:hint="@string/equipment_hint"
android:background="@drawable/border"/>
</LinearLayout>
<View android:id="@+id/unit_overlay"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:background="@color/gray_overlay"
/>
</RelativeLayout>
的例子來說明我想要的東西:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/unit_entry"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingBottom="3dip">
<TextView
android:id="@+id/text1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="text1"/>
<TextView
android:id="@+id/text2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/text1"
android:text="text2"/>
<View android:id="@+id/unit_overlay"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:background="#88666666"
/>
</RelativeLayout>
在這個例子中,我想unit_overlay既包括文本1和文本。
你可以發佈您的包含的佈局呢?因爲我可以在沒有它們的情況下運行這個代碼。 –
爲什麼在你的視圖中有一個android:orientation =「vertical」? – TheRedFox
@FarukYazıcı增加了一個更容易測試的例子。 – schoel