[英]Set aspect ratio in PercentageRelativeLayout programmatically
[英]Set PercentageRelativeLayout margin programmatically
请问,如何以编程方式设置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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.