【问题标题】:AChartEngine - GraphicalView always match parentAChartEngine - GraphicalView 总是匹配父级
【发布时间】:2015-02-05 20:33:03
【问题描述】:

我创建了一个GraphicalViewCombinedXYChartView)并将其添加到我的布局中。接下来,我想在我的 GraphicalView 下面添加一些 CheckBoxes

问题是,GraphicalView 总是匹配父级,这就是为什么我看不到我的复选框(因为它们没有空间)。

这是截图:

这是我的代码(截断):

layout_chart.xml

<?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:background="@color/background_color"
android:orientation="vertical" >

<!-- layout for chart -->
<LinearLayout
    android:id="@+id/linearLayout_chart"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >
</LinearLayout>

<!-- layout for checkboxes -->
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <CheckBox
        android:id="@+id/checkBox1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:checked="true"
        android:text="checkBox1" />
    <CheckBox
        android:id="@+id/checkBox2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:checked="true"
        android:text="checkBox2" />
</LinearLayout>
</LinearLayout>

FragmentChart.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    LinearLayout v = (LinearLayout) inflater.inflate(R.layout.layout_chart, container, false);
    graphicalView = initChart();  // Creating CombinedXYChartView
    LinearLayout layout = (LinearLayout) v.findViewById(R.id.linearLayout_chart);
    layout.addView(graphicalView, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    return v;
}

图表完美运行。如果我禁用图表,还有复选框。那么,有什么问题呢?

【问题讨论】:

    标签: android layout view achartengine fill-parent


    【解决方案1】:

    我认为您需要添加权重以让图表知道它需要共享一些空间。更新您的 xml,使其在包含复选框的线性布局中的权重属性为 1。

    <?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:background="@color/background_color"
         android:orientation="vertical" >
    
      <!-- layout for chart -->
     <LinearLayout
         android:id="@+id/linearLayout_chart"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:orientation="vertical" >
     </LinearLayout>
    
     <!-- layout for checkboxes -->
     <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_weight="1"
         android:orientation="horizontal" >
    
    <CheckBox
        android:id="@+id/checkBox1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:checked="true"
        android:text="checkBox1" />
    <CheckBox
        android:id="@+id/checkBox2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:checked="true"
        android:text="checkBox2" />
    </LinearLayout>
     </LinearLayout>
    

    【讨论】:

    • 是的,我只是以同样的方式解决了这个问题(并且正在输入一个答案)。总是一样的......我试图找到一个大约 1-2 小时的解决方案,在我提出关于 stackoverflow 的问题后不久,我自己得到了它。不过还是谢谢啦!
    猜你喜欢
    • 1970-01-01
    • 2023-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多