在SO中阅读多个问题/答案后,我仍然在寻找答案
我的问题:在我的应用程序中,我使用工具栏,但根据片段/活动,您在工具栏菜单项中可能会更改,例如,在第一个屏幕上您将只看到一个Textview,在另一个片段中将会有主页箭头和溢出菜单有时有两个菜单图标。问题是标题以可用的空间为中心(工具栏空间 - 菜单空间)
这是我的工具栏xml:
AmCharts.addInitHandler(function(chart) {
// do nothing if seriesField is not set and seriesValueField isn't set or is not an array
if (chart.seriesField === undefined && (chart.seriesValueField === undefined || chart.seriesValueField.length === 0))
return;
// get graphs and dataProvider
var graphs, dataSet;
if (chart.type === "stock") {
// use first panel
if (chart.panels[0].stockGraphs === undefined)
chart.panels[0].stockGraphs = [];
graphs = chart.panels[0].stockGraphs;
dataSet = chart.dataSets[0];
// check if data set has fieldMappings set
if (dataSet.fieldMappings === undefined)
dataSet.fieldMappings = [];
} else {
if (chart.graphs === undefined)
chart.graphs = [];
graphs = chart.graphs;
dataSet = chart;
}
// collect value fields for graphs that might already exist
// in chart config
var valueFields = {};
if (graphs.length) {
for (var i = 0; i < graphs.length; i++) {
var g = graphs[i];
if (g.id === undefined)
g.id = i;
valueFields[g.id] = g.valueField;
}
}
// process data
var newData = [];
var dpoints = {};
for (var i = 0; i < dataSet.dataProvider.length; i++) {
// get row data
var row = dataSet.dataProvider[i];
var category = row[dataSet.categoryField];
// create a data point
if (dpoints[category] === undefined) {
dpoints[category] = {};
dpoints[category][dataSet.categoryField] = category;
newData.push(dpoints[category]);
}
//add points and create graphs for each seriesField + seriesValueField combination
chart.seriesValueFields.forEach(function(seriesValueField) {
var series = chart.seriesField + ' ' + row[chart.seriesField] + ' ' + seriesValueField;
// check if we need to generate a graph
if (valueFields[series] === undefined) {
// apply template
var g = {};
if (chart.seriesGraphTemplate !== undefined) {
g = cloneObject(chart.seriesGraphTemplate);
}
g.id = series;
g.valueField = series;
g.title = series;
// add to chart's graphs
graphs.push(g);
valueFields[series] = series;
// add fieldMapping to data set on Stock Chart
if (chart.type === "stock") {
dataSet.fieldMappings.push({
"fromField": series,
"toField": series
});
}
}
// add series value field
if (row[seriesValueField] !== undefined) {
dpoints[category][series] = row[seriesValueField];
}
});
// add the rest of the value fields (if applicable)
for (var field in valueFields) {
if (valueFields.hasOwnProperty(field) && row[field] !== undefined)
dpoints[category][field] = row[field];
}
}
// set data
dataSet.dataProvider = newData;
// function which clones object
function cloneObject(obj) {
if (null == obj || "object" != typeof obj) return obj;
var copy = obj.constructor();
for (var attr in obj) {
if (obj.hasOwnProperty(attr)) copy[attr] = obj[attr];
}
return copy;
}
}, ["serial", "stock"]);
// ...
AmCharts.makeChart("chartdiv", {
// ...
"seriesField": "day",
"seriesValueFields": ["foo1", "foo3"],
"seriesGraphTemplate": {
"lineThickness": 2,
"type": "smoothedLine",
"useDataSetColors": false,
"bullet": "round"
},
// ...
});
正如您所看到的,我尝试了contentInserStart但它没有改变任何东西。我还使用了relativelayout来中心textview。我需要它至少在API 19上工作(在我的手机上试试)。
即使我有菜单项,是否有解决方案将Textview置于栏中间?
修改
找不到任何解决方案我只是在RelativeLayout中添加了一个Image视图,就像主页按钮一样。