2016-09-07 61 views
0

我有一個Viewgroup作爲包含背景圖像的相關佈局的父級佈局。我將動態添加到relativelayout並可以縮放和滾動它。當我改變方向時,背景圖像縮小以適應風景。我想按照背景圖像的比例更改相關佈局控件。 Iam新手到Android,所以不清楚從哪裏開始?android-根據背景圖像按比例改變佈局

佈局

<com.example.pdoc.zoomablepdf.ZoomableViewGroup 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:foregroundGravity="center" 
android:id="@+id/zoomLayout" 
xmlns:android="http://schemas.android.com/apk/res/android"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:gravity="center" 
     android:background="@drawable/sample1pdf" 
     android:id="@+id/RelLayout">    
    </RelativeLayout> 
    </com.example.pdoc.zoomablepdf.ZoomableViewGroup> 

回答

0

您可以創建不同的方向不同的佈局。通過這種方式,可以很容易地維護任何方向的用戶界面組件。

+0

其實我只是想相稱的控制WRT背景圖片,所以我不能爲創造一個不同的佈局......怎麼把背景圖像也會動態變化,控件動態添加 –

0

我想你可以使用onConfigurationChanged監聽器。 像這樣

@Override 
     public void onConfigurationChanged(Configuration newConfig) { 
      super.onConfigurationChanged(newConfig); 

      // Checks the orientation of the screen 
      if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) { 

       //Make your layout changes 
      } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){ 
       //other Changes (to default) 
      } 
     } 

你可以看看這裏的更多信息:How to detect orientation

+0

其實我正在使用這個事件並確定方向,我的問題是如何按比例動態添加控件和背景圖像。由於bg圖像的高度和寬度根據方向而改變,但是添加的控件的大小較早..我希望它們按比例,它們看起來只是圖像的一部分.. –