簡體   English   中英

嵌套線性布局未顯示

[英]Nested Linear Layout Not Showing

在這里,我附加了Layout的xml代碼。當我看到以下代碼的設計視圖時,它看起來如下所示。

在此處輸入圖片說明

但是,當我通過他的圖以編程方式更新了內部線性布局(chart_container)時,它沒有顯示“查看日志”按鈕。

在此處輸入圖片說明

我在這里也添加了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); 

嘗試像這樣更改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" >

更好的解決方案是將您的top linearlayout放在scrollview中。

暫無
暫無

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

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