我想以几种格式使用相同的布局。因此,我必须更改大小。
如何使用ID picframe编程地更改Relativelayout的宽度?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/item_frame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:gravity="left"
android:layout_centerVertical="true">
<RelativeLayout
android:id="@+id/picframe"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:layout_marginRight="10dp" >
<ImageView
android:id="@+id/picture"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitCenter"
android:layout_centerInParent="true"
android:adjustViewBounds="true"
android:contentDescription="@string/app_name" />
<ImageView
android:id="@+id/overlay"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitCenter"
android:layout_centerInParent="true"
android:adjustViewBounds="true"
android:contentDescription="@string/app_name" />
...
我尝试了
remoteView.setString(R.id.picframe, "setWidth", "50dp");
和
remoteView.setString(R.id.picframe, "setLayoutWidth", "50dp");
没有成功。
我不会尝试。我将顶级视图视为<merge>
,而不是相对布局,并将其合并为具有所需宽度的相对布局。