gpt4 book ai didi

android - 如何以编程方式更改 Android ListView 的布局边距

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:19:28 24 4
gpt4 key购买 nike

我在 xml 中定义了一个 ListView ,如下所示

     <ListView android:id="@+id/mylist" 
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:cacheColorHint="#00000000"
android:layout_weight="1"
android:layout_marginTop="95dip"/>

我需要根据程序中的某些结果重新定义布局边距,我该如何实现这一点

最佳答案

更简单地说,您可以修改现有的 MarginLayoutParams 实例来修改边距:

ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams) mListView
.getLayoutParams();

mlp.setMargins(adjustmentPxs, 0, 0, 0);

break;

关于android - 如何以编程方式更改 Android ListView 的布局边距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3061579/

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