簡體   English   中英

相對布局子項占據整個屏幕高度

[英]Relative Layout child taking full height of screen

我正在嘗試獲取活動中的圖表和3個按鈕。 3個按鈕應在圖表下方對齊。 我有以下XML,但是按鈕僅被圖表抑制(為清晰起見,請編輯:按鈕不可見。)

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".PlotActivity">

    <com.github.mikephil.charting.charts.LineChart
        android:id="@+id/chart"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"/>

    <Button
        android:id="@+id/one_week_preset_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/chart"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:text="@string/one_week_label" />

    <Button
        android:id="@+id/one_month_preset_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/chart"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:text="@string/one_month_label" />

    <Button
        android:id="@+id/download_new_data_and_update_graph"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/chart"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:text="@string/download_and_update_label" />

</RelativeLayout>

我很確定這可以通過線性布局的兩層嵌套輕松完成,但是這種XML的問題是什么以及如何解決。 任何幫助表示贊賞。

上面的XML產生以下屏幕,如android studio所示(請注意,圖表占據了整個屏幕,因此按鈕不可見)

圖表占用完成屏幕

使用圖表競爭以此。 這是因為您要告訴布局將父項的頂部和wrap_content對齊(可能與父項的底部對齊)。 您應該告訴它應該從底部開始。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".PlotActivity">

<com.github.mikephil.charting.charts.LineChart
    android:id="@+id/chart"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_above="@+id/one_week_preset_button"
/>

<Button
    android:id="@+id/one_week_preset_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:text="@string/one_week_label" />

<Button
    android:id="@+id/one_month_preset_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:text="@string/one_month_label" />

<Button
    android:id="@+id/download_new_data_and_update_graph"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:text="@string/download_and_update_label" />

</RelativeLayout>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM