Android在横向模式下不会自行拉伸布局
我正在尝试将两个图像置于横向模式,因为我的应用程序将在横向模式下运行。当我这样做的时候,android在potrait模式下正常工作,但在横向模式下,它不会随着比例的增加而延长,但它们保持不变。我应该怎么做才能让android处理它Android在横向模式下不会自行拉伸布局,android,android-layout,Android,Android Layout,我正在尝试将两个图像置于横向模式,因为我的应用程序将在横向模式下运行。当我这样做的时候,android在potrait模式下正常工作,但在横向模式下,它不会随着比例的增加而延长,但它们保持不变。我应该怎么做才能让android处理它 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<FrameLayout
android:id="@+id/frameLayout1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:layout_gravity="center_horizontal" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/hud" />
</FrameLayout>
<FrameLayout
android:id="@+id/frameLayout2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:layout_gravity="center_horizontal">
<ImageView
android:id="@+id/imageView2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal"
android:src="@drawable/bg" />
</FrameLayout>
</LinearLayout>
如果希望应用程序始终处于横向模式,请在清单文件中进行如下设置:
<activity android:screenOrientation="landscape">
然后,您可以使用此显示宽度来设置图像的宽度(即宽度/2)。您的图像视图上可能需要安卓:scaleType=“fitCenter”。不相关,但您不应混合使用
填充父对象
和匹配父对象
。如果您的目标API为1.6+,请使用fill\u parent
。使用match\u parent
如果你的目标是2.1+的API。使用LinearLayout而不是FrameLayout,那么你还应该使用android:layout\u weight=“1”来更好地理解你想要做什么?是否要在横向模式下修复布局?或者想对ImageView执行其他操作?为了获得最佳实践,请对ImageView的宽度和高度使用wrap_内容。
/* First, get the Display from the WindowManager */
Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
/* Now we can retrieve all display-related infos */
int width = display.getWidth();