android - 可以通过编程设置LayoutParams为fragment吗

标签 android android-layout

如何以编程方式LayoutParams设置为Fragment

实际上:我想将两个 Fragments 添加到 LinearLayout 以编程方式 并且我需要设置 android:layout_weight他们。我是 Fragment 的新手。我不知道将两个 Fragments 添加到一个 Layout

是否是一个好方法

对不起。我的英语不是很好。

最佳答案

LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT);
params.weight = 3.0f;
fragment.getView().setLayoutParams(params);

关于android - 可以通过编程设置LayoutParams为fragment吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12224433/

相关文章:

android - 约束布局 : center view on full screen but limit width to not overlap with side views

android - 在 android 中打开键盘时如何在 View 中滚动?

android - windowBackground 上的居中图像与膨胀布局上的图像不同

Android RecyclerView 绘图问题(闪烁)

Android将占位符文本添加到EditText

android - FloatingActionButton、layout_anchor 和 layout_gravity

android - 只有在 GridLayout 中显示 ViewGroup 的第一个 subview - 后续单元格在视觉上是无 subview 的

android ListView 创建一个 3 列 View

android - Ubuntu 9.10 中的 Nexus One Android 调试

Android MediaPlayer 在 2.1 上抛出 "Prepare failed.: status=0x1",适用于 2.2