android - 以编程方式更改 ScrollView 权重

标签 android

我想改变 ScrollView 的权重,但我找不到方法。

这是我的 XML:

<ScrollView
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:layout_gravity="center_vertical"
    android:id="@+id/firstScrollView">

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        ...
    </LinearLayout>

   **other layout..

</ScrollView>

从代码中我只能设置scrollView的高度或宽度,我应该为权重写什么?

    ViewGroup.LayoutParams scrollParams = new ViewGroup.LayoutParams(width,height);
    scrollView.setLayoutParams(scrollParams);

最佳答案

 LinearLayout.LayoutParams scrollParams = new LinearLayout.LayoutParams(width,height,2.0f);
 scrollView.setLayoutParams(scrollParams);

构造函数中的最后一个选项是权重

关于android - 以编程方式更改 ScrollView 权重,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28481618/

相关文章:

android - AVD Manager 在关闭并重新打开自身后丢失用户创建的设备定义

android - 使用libgdx应用程序在Eclipse中启用Multidex

android - 多次显示相同布局的更好方法是什么?

android - 创建一个新的 Android 应用程序项目

android - 处理程序不会绑定(bind)到主线程

Android MP4 流 - 无法播放视频

android - Android 中的 "public float getFocalLength ()"和 "public void getFocusDistances (float[] output)"有什么区别?

java - 如何在 Activity 中将查询结果原始显示为表格?

1490086 字节的 Android 错误 : I/dalvikvm-heap: Grow heap (frag case) to 16. 159MB

android - Google Play 服务可以在应用内使用 cookie 吗?