2017-02-25 95 views
1

我想以多種格式使用相同的佈局。因此,我必須改變尺寸。如何更改appwidget中佈局對象的寬度?

如何以編程方式更改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"); 

沒有成功。

回答

0

我不會嘗試。我會使頂層視圖爲<merge>而不是相對佈局,並將其合併到您希望的寬度的相對佈局中。

+0

感謝提供'合併'標籤的提示,但在這種情況下,這是需要的,因爲佈局比你在這個sniplet中看到的要複雜。 – Wookiee