嵌套线性布局不显示
Nested Linear Layout Not Showing
这里我附上了 Layout.When 的 xml 代码 我看到以下代码的设计视图如下所示。
但是当我通过图表以编程方式更新内部线性布局 (chart_container) 时,它没有显示查看日志按钮。
我也在这里添加了 Java 代码,我用它来更新内部线性 layout.Please 谁能告诉我为什么那个按钮没有出现在屏幕底部。
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" >
更好的解决方案是将线性布局放在滚动视图的顶部。
这里我附上了 Layout.When 的 xml 代码 我看到以下代码的设计视图如下所示。
但是当我通过图表以编程方式更新内部线性布局 (chart_container) 时,它没有显示查看日志按钮。
我也在这里添加了 Java 代码,我用它来更新内部线性 layout.Please 谁能告诉我为什么那个按钮没有出现在屏幕底部。
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" >
更好的解决方案是将线性布局放在滚动视图的顶部。