当我有 1、2 或 3 个组件时,我知道如何让它们正确放置。但现在我有一个 View ,其中包含 4、5、... 组件。我不需要增加组件的尺寸(通过重量),而是需要它们保持固定的尺寸。那么...有什么方法可以以合理的间距(在 View 内均匀分布)来布局它们?
谢谢
J
最佳答案
我发现的一个类似的解决方法是添加间隔 View 组件。同样,这并不理想,但它确实有效。如果有更好的,请告诉我。
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<biz.mycompany.mycomponent
android:layout_width="@dimen/screen_view_w"
android:layout_height="@dimen/screen_view_h"
/>
<View
android:layout_width="0px"
android:layout_height="@dimen/main_screen_button_h"
android:layout_weight="1"
/>
<biz.mycompany.mycomponent2
android:layout_width="@dimen/screen_view_w"
android:layout_height="@dimen/screen_view_h"
/>
<View
android:layout_width="0px"
android:layout_height="@dimen/screen_view_h"
android:layout_weight="1"
/>
<biz.mycompany.mycomponent3
android:layout_width="@dimen/screen_view_w"
android:layout_height="@dimen/screen_view_h"
/>
</LinearLayout>
关于android - 如何: Layout fixed size components with justified spacing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4400991/