2016-09-07 49 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图像的高度和宽度根据方向而改变,但是添加的控件的大小较早..我希望它们按比例,它们看起来只是图像的一部分.. –