我必须在屏幕上定义5个布局,并将它们放置为3x3网格。布局是空的。 定义最大RelativeLayout大小
在某些时候我希望以编程方式在一个布局上添加一些视图,并且该视图不得超过分配的布局大小。换句话说,我想要在其中放置任何视图的布局,并且它将保证它不会在该布局上增长。重要说明:我无权手动更改添加视图的大小,我只能控制其最大大小。
我现在所拥有的这样的布局:
<RelativeLayout
android:id="@+id/pluginsLayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/mainButtons"
android:layout_below="@+id/paramsLayout">
<RelativeLayout
android:id="@+id/capturingPluginLayout"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="fill_horizontal|left"
android:layout_above="@+id/processingPluginLayout">
</RelativeLayout>
<RelativeLayout
android:id="@+id/processingPluginLayout"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="fill_horizontal|left"
android:layout_above="@+id/filterPluginLayout">
</RelativeLayout>
<RelativeLayout
android:id="@+id/filterPluginLayout"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="fill_horizontal|left|bottom"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true">
</RelativeLayout>
<RelativeLayout
android:id="@+id/exportPluginLayout"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="fill_horizontal|right"
android:layout_above="@+id/viewfinderPluginLayout">
</RelativeLayout>
<RelativeLayout
android:id="@+id/viewfinderPluginLayout"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="fill_horizontal|bottom|right"
android:layout_toLeftOf="@+id/filterPluginLayout"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true">
</RelativeLayout>
</RelativeLayout>
我在代码中增加了新的观点:
public void addVFPluginView(View view)
{
((RelativeLayout)MainScreen.thiz.findViewById(R.id.viewfinderPluginLayout)).addView(view);
}
我希望有这样的行为:
但我只有这样,查看填充整个父级布局:
注:我用API8(没有网格布局)
oh..u'r右...为什么我在记忆中有其他的东西? )会尝试网格! – Grinchman
我再次阅读文档,发现GridLayout存在API14以后,而不是API8 ... – Grinchman
尝试使用示例。它会工作。当然。我用了2.2 – mainu