change xml value android:layout_marginStart of ImageView in



我创建了一个带有ImageView小部件的xml文件,我想用Java编程方式改变这个ImageView的xml值android:layout_marginStart的位置。我想在Java中设置该值并更新Widget。我怎样才能改变这个值?findVIewById不能用于Widgets…

<ImageView
android:id="@+id/plane"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="100dp" <-- i want to change this value with java code
android:contentDescription="@string/plane"
android:src="@drawable/plane"/>

有方法remoteView.setViewPadding(left,right,top,bottom)。确保您的小部件到处都有match_parent和wrap_content,然后您可以轻松地使用Padding以编程方式更改图像的位置。也许你还得加上android:cropToPadding="true"

最新更新