gpt4 book ai didi

java - TableRow 权重缩放与我在 Android java 应用程序中使用 GraphView 时的预期相反

转载 作者:行者123 更新时间:2023-12-01 12:37:24 26 4
gpt4 key购买 nike

我创建了以下布局 xml 文件:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="some.package.MainActivity" >

<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>

<TableRow
android:id="@+id/mainRow"
android:layout_weight="1" >

<FrameLayout
android:id="@+id/mainLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" />
</TableRow>

<TableRow
android:id="@+id/footerRow"
android:layout_weight="1" >

<FrameLayout
android:id="@+id/footerLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" />
</TableRow>
</TableLayout>

</RelativeLayout>

...并使用 GraphView api 中的图表填充它,如下所示:

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

int[] assetLayouts = new int[]{
R.id.mainLayout,
R.id.footerLayout,
};
int count = 0;
for (int assetLayout :assetLayouts ) {
GraphViewSeries exampleSeries = new GraphViewSeries(new GraphViewData[] {
new GraphViewData(1, 2.0d)
, new GraphViewData(2, 1.5d)
, new GraphViewData(3, 2.5d)
, new GraphViewData(4, 1.0d)
});

GraphView graphView = new LineGraphView(this, "" + ++count);
graphView.addSeries(exampleSeries);

FrameLayout layout = (FrameLayout) findViewById(assetLayout);
layout.addView(graphView);
}
}

其行为符合预期,并将屏幕分为两部分,一个图形占据上半部分,第二个图形占据另一下半部分。现在,我想赋予顶部图形/行更多的权重,即它应该按比例大于下部图形/行。因此,我所做的是将顶行 (mainRow) 设置为 android:layout_weight="2"。我预计顶行现在应该是底行的两倍,但是,情况恰恰相反。顶部的仅占据 33%,而底部的则占据 66% 的屏幕空间。这与我找到的文档相反:

For example, if there are three text fields and two of them declare a weight of 1, while the other is given no weight, the third text field without weight will not grow and will only occupy the area required by its content. The other two will expand equally to fill the space remaining after all three fields are measured. If the third field is then given a weight of 2 (instead of 0), then it is now declared more important than both the others, so it gets half the total remaining space, while the first two share the rest equally.

http://developer.android.com/guide/topics/ui/layout/linear.html

这是怎么回事?

当然,我可以解决这个问题,只是给出与我认为正确的相反的权重,但我宁愿做正确的事情。

最佳答案

此外,在设置权重时,请将宽度(如果方向为水平)或高度(如果为垂直)设置为 0dp。这样宽度/高度就可以正确计算。

关于java - TableRow 权重缩放与我在 Android java 应用程序中使用 GraphView 时的预期相反,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25467063/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com