2014-02-12 30 views
0

我有類似的東西:編程調整的FrameLayout

<FrameLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@drawable/photo1" 
      android:orientation="vertical" > 
    <FrameLayout 
       android:id="@+id/photo2" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" > 

    </FrameLayout> 
    <Fragment> 

</Fragment> 
    </FrameLayout> 

我想調整該照片2的FrameLayout。

public void setScreenSize() { 
    Display display = getWindowManager().getDefaultDisplay(); 
    FrameLayout layout = (FrameLayout) findViewById(R.id.photo2); 
    int screen_height = display.getHeight(); 
    screen_height = (int) (0.60*screen_height); 
    LayoutParams parms = (LayoutParams) layout.getLayoutParams(); 
    parms.height = screen_height; 
    } 

不幸的是,這不起作用,我不知道爲什麼。

+0

你有沒有發現我上面的代碼都試過,但沒有我的情況 – PriyankaChauhan

回答

1

您是否將高度設置回佈局?

public void setScreenSize() { 
    Display display = getWindowManager().getDefaultDisplay(); 
    FrameLayout layout = (FrameLayout) findViewById(R.id.photo2); 
    int screen_height = display.getHeight(); 
    screen_height = (int) (0.60*screen_height); 
    LayoutParams parms = (LayoutParams) layout.getLayoutParams(); 
    parms.height = screen_height; 
    // Set it back. 
    layout.setLayoutParams(parms); 
} 
0

如果你想改變FrameLyaout的大小編程然後複製並粘貼此代碼,它的工作100%。

FrameLayout frame1 = (FrameLayout) findViewById(R.id.framelayout1); 
frame1.getLayoutParams().height =460; 
frame1.getLayoutParams().width = 350; 
frame1.requestLayout(); 
+0

代碼 – PriyankaChauhan

+0

工作,你可以分享我的任何回答 –

+0

actualImageBitmap = BitmapFactory.decodeFile(新文件(Datas.received_uri.getPath())。 getAbsolutePath(),options); ImageViewHeight = options.outHeight; ImageViewWidth = options.outWidth; img_baseview.setScaleType(ImageView.ScaleType.MATRIX); canvasView.getLayoutParams()。height = ImageViewHeight; canvasView.getLayoutParams()。width = ImageViewWidth; canvasView.requestLayout(); – PriyankaChauhan