gpt4 book ai didi

android - 以编程方式设置 PercentageRelativeLayout 边距

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:25:17 26 4
gpt4 key购买 nike

请问,如何以编程方式设置 imageview 的边距百分比。

<android.support.percent.PercentRelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<ImageView
android:id="@+id/rating_thumb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/thumb" />

</android.support.percent.PercentRelativeLayout>

最佳答案

经过几个小时的谷歌搜索和调整,我终于得到了答案。

imageView =  (ImageView) view.findViewById(R.id.rating_thumb);
PercentRelativeLayout.LayoutParams layoutParams = (PercentRelativeLayout.LayoutParams) imageView.getLayoutParams();
PercentLayoutHelper.PercentLayoutInfo percentLayoutInfo = layoutParams.getPercentLayoutInfo();
percentLayoutInfo.leftMarginPercent = 15 * 0.01f; //15 is the percentage value you want to set it to
imageView.setLayoutParams(layoutParams);

关于android - 以编程方式设置 PercentageRelativeLayout 边距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35066989/

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