[英]android - change layout in proportion to background image on orientation
我有一个以Viewgroup为父的布局,其中包含带有背景图像的relativelayout。 我将控件动态添加到relativelayout并能够缩放和滚动它。 当我改变方向时,背景图像会缩小以适合横向。 我想按背景图像的比例更改相对布局控件。 我是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>
您可以为不同的方向创建不同的布局。 这样,很容易针对任何方向维护UI部件。
我认为您可以使用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)
}
}
您可以在此处查看更多信息: 如何检测方向
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.