我需要以下事情:3佈局 - 中間是靈活
3佈局:
- 頭
- 內容
- 頁腳
頭必須在頂部頁腳必須堅持到底(android:layout_alignParentBottom="true"
)。
但是如何讓中間佔據整個其他屏幕?謝謝。
我需要以下事情:3佈局 - 中間是靈活
3佈局:
頭必須在頂部頁腳必須堅持到底(android:layout_alignParentBottom="true"
)。
但是如何讓中間佔據整個其他屏幕?謝謝。
使用的0dp的高度和
android:layout_weight
設置爲1
它必須是LinearLayout – Blackbelt
在這種情況下,您不需要將高度設置爲0dp,並且是的,這可以很好地作爲線性佈局的子項。 –
這裏是我的解決方案(與Android:layout_weight和滾動型):
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#DDDDDD"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Header"
tools:ignore="HardcodedText" />
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="3" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Content"
tools:ignore="HardcodedText" />
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#DDDDDD"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Footer"
tools:ignore="HardcodedText" />
</LinearLayout></LinearLayout>
而且效果圖:
但如果我想要頁眉和頁腳是一些特定的大小和內容 - 整個剩餘空間? – Volodymyr
是否可以在你的問題中制定計劃?然後我改變我的答案。 –
@Volodymyr ScrollView可能會有用,如果您在內容佈局中使用內容溢出屏幕 –
最後,我已經得到了一個解決方案:
到中間佈局我說:
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/footer"
android:layout_below="@id/header"
android:layout_weight="1">
和它的作品!
嗨使用以下行
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text="Button" >
<Button
android:id="@+id/button2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Header" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/linearfooter"
android:layout_below="@+id/button1"
android:background="@android:color/darker_gray"
>
</LinearLayout>
<LinearLayout
android:id="@+id/linearfooter"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Button" >
<Button
android:id="@+id/button2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="footer" />
</LinearLayout>
</RelativeLayout>
希望這可以幫助你。
layout_height =「fill_parent」 – Blackbelt
不,在這種情況下,中間的一個將顯示在頁腳佈局上。 – Volodymyr
是的。 「fill_parent」的確切含義取決於容器類,但在大多數情況下,它意味着「搶佔所有剩餘空間」。在這種情況下,Lopez在下面有正確的答案,即使用** android:layout_weight **在佈局時給視圖指定所有多餘的空間。 –