嵌套线性布局未显示

时间:2015-04-13 05:03:07

标签: android android-layout android-linearlayout

这里我附加了Layout的xml代码。当我看到以下代码的设计视图时,它如下所示。

enter image description here

但是当我通过图形以编程方式更新内部线性布局(chart_container)时,它没有显示视图日志按钮。

enter image description here

我在这里也添加了Java代码,我用它来更新内部线性布局。请告诉我为什么Button没有出现在屏幕底部。

layout.xml

<?xml version="1.0" encoding="utf-8"?>
         <LinearLayout     xmlns:android="http://schemas.android.com/apk/res/android"
         android:id="@+id/linear1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@color/white"
        android:orientation="vertical" >
        <TableLayout
            android:id="@+id/table1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:shrinkColumns="6"
            android:stretchColumns="*" >
            <TableRow
                android:id="@+id/tableRow1"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:background="#4CC1D2"
                android:padding="4dip" >
                <ImageButton
                    android:layout_width="match_parent"
                    android:layout_height="40dp"
                    android:layout_gravity="left"
                    android:layout_span="1"
                    android:background="#4CC1D2"
                    android:onClick="gotoback"
                    android:src="@drawable/backb" />
                <TextView
                    android:id="@+id/currentMonth"
                    android:layout_width="wrap_content"
                    android:layout_height="40dp"
                    android:layout_marginLeft="-28dp"
                    android:layout_span="5"
                    android:gravity="left"
                    android:text="How You want to Track"
                    android:textColor="#ffffff"
                    android:textSize="21sp"
                    android:textStyle="bold" />
            </TableRow>
            <TableRow
                android:id="@+id/tableRow2"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:background="#04B404"
                android:padding="2dip" >
            </TableRow>
        </TableLayout>
        <TableLayout
            android:id="@+id/table2"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:shrinkColumns="9"
            android:stretchColumns="*" >
            <TableRow
                android:id="@+id/tableRow2"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:background="#58D3F7"
                android:padding="10dip" >
                <TextView
                    android:id="@+id/lstweek"
                    android:layout_width="wrap_content"
                    android:layout_height="40dp"
                    android:layout_span="3"
                    android:background="#4cc1d2"
                    android:gravity="center"
                    android:text="Last Week"
                    android:textColor="#ffffff"
                    android:textSize="18sp"
                    android:textStyle="bold" />
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="40dp"
                    android:layout_span="3"
                    android:background="#4cc1d2"
                    android:clickable="true"
                    android:gravity="center"
                    android:onClick="getmonth"
                    android:text="Last 30 Days"
                    android:textColor="#ffffff"
                    android:textSize="18sp"
                    android:textStyle="bold" />
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="40dp"
                    android:layout_span="3"
                    android:background="#4cc1d2"
                    android:clickable="true"
                    android:gravity="center"
                    android:onClick="getmonth1"
                    android:text="     All     "
                    android:textColor="#ffffff"
                    android:textSize="18sp"
                    android:textStyle="bold" />
            </TableRow>
            <TableRow
                android:id="@+id/tableRow2"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:background="#04B404"
                android:padding="2dip" >
            </TableRow>
        </TableLayout>
        <LinearLayout
            android:id="@+id/chart_container"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@color/white"
            android:orientation="vertical" >
     </LinearLayout>
     <View
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:layout_weight="1" />
            <Button
                android:id="@+id/logs7"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:background="#4CC1D2"
                android:onClick="alllogs"
                android:text="View Logs"
                android:textColor="#FFFFFF"
                android:textSize="22dp"
                android:textStyle="bold" />
    </LinearLayout>

Java代码

LinearLayout chartContainer = (LinearLayout) findViewById(R.id.chart_container);
                            chartContainer.setBackgroundColor(Color.WHITE);
                            LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
                                    LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);

                            chartContainer.setScrollContainer(true);


                            LinearLayout con = (LinearLayout) findViewById(R.id.linear1);
                            con.setBackgroundColor(Color.WHITE);





                            // Specifying chart types to be drawn in the graph
                            // Number of data series and number of types should be same
                            // Order of data series and chart type will be same
                            String[] types = new String[] { LineChart.TYPE, BarChart.TYPE };

                            // Creating a combined chart with the chart types specified in types array
                            mChart = (GraphicalView) ChartFactory.getCombinedXYChartView(getBaseContext(), dataset, multiRenderer, types);
                            mChart.setBackgroundColor(Color.WHITE);
                            multiRenderer.setClickEnabled(true);
                            multiRenderer.setSelectableBuffer(10);

                            multiRenderer.setXLabelsAngle(45.0f);
                            multiRenderer.setYLabelsAngle(30.0f);
                            multiRenderer.setBarWidth(10);

                            multiRenderer.setXLabelsAlign(Align.CENTER);

                            multiRenderer.setXAxisMax(7.5);

                            multiRenderer.setOrientation(Orientation.HORIZONTAL);
                            // Adding the Combined Chart to the LinearLayout
                            chartContainer.addView(mChart,layoutParams); 

1 个答案:

答案 0 :(得分:3)

尝试更改chart_container,如下所示:

<LinearLayout
    android:id="@+id/chart_container"
    android:layout_width="wrap_content"
    android:layout_height="0dip"
    android:layout_weight="1"
    android:background="@color/white"
    android:orientation="vertical" >

更好的解决方案是在scrollview中将top linearlayout。