0

我想在活动中得到一个图表和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产生下面的屏幕所示机器人工作室(请注意,图占据整个屏幕,并因此按钮不可见)

Chart Occupying complete screen

+0

什么用线型图的,你也尝试使用它的另一种观点就地,请与像EDITTEXT或查看其他视图检查,保证,有什么是我们必须解决这个问题,谢谢 – Androider

+0

@Androider折线图用于显示图表(图表)。它来自'mpandroidchart'库,用于绘制图表。问题在于,按照您在图像中看到的方式,按钮并未显示在布局中。 –

回答

1

使用图表争夺作为此。这是因为你正在告诉布局来对齐父顶层和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> 
+0

我收到了一个异常,说'循环依赖关系不能存在于相关布局中' –

+0

没问题。得到它了。从固定它的按钮中移除'layout_below'。 –

+0

是的,这是什么问题。 – Arslan

相关问题