Android 相对线内的框架布局
我有两个布局,一个是背景,另一个是在它的中心,占据了大约一半的屏幕。我有我认为可以做到这一点的代码,但是当应用程序运行时,我包含的视图占据了整个屏幕,我不明白为什么会发生这种情况Android 相对线内的框架布局,android,xml,Android,Xml,我有两个布局,一个是背景,另一个是在它的中心,占据了大约一半的屏幕。我有我认为可以做到这一点的代码,但是当应用程序运行时,我包含的视图占据了整个屏幕,我不明白为什么会发生这种情况 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<include
android:layout_width="500dp"
android:layout_height="500dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
layout="@layout/activity_main" />
</RelativeLayout>
第二个xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#00000000" >
<FrameLayout
android:id="@+id/frmPreview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center" >
</FrameLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="left"
android:gravity="center_vertical"
android:orientation="vertical" >
</LinearLayout>
<ImageView
android:id="@+id/imgShoot"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="bottom|center"
android:background="@drawable/aperture_closing" />
尝试使用砝码
android:layout_weight="1"
除了
标记上的布局
之外,您不能指定任何属性,因为它将被包含的布局的根元素完全替换,并且它们将被删除。此外,您不需要使用RelativeLayout
将孩子居中。出于性能原因,最好使用框架布局
家长:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/activity_main" />
</RelativeLayout>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="500dp"
android:layout_height="500dp"
android:layout_gravity="center"
android:background="#00000000">
<FrameLayout
android:id="@+id/frmPreview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center">
</FrameLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="left"
android:gravity="center_vertical"
android:orientation="vertical">
</LinearLayout>
<ImageView
android:id="@+id/imgShoot"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="bottom|center"
android:background="@drawable/aperture_closing"/>
</FrameLayout>
儿童:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/activity_main" />
</RelativeLayout>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="500dp"
android:layout_height="500dp"
android:layout_gravity="center"
android:background="#00000000">
<FrameLayout
android:id="@+id/frmPreview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center">
</FrameLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="left"
android:gravity="center_vertical"
android:orientation="vertical">
</LinearLayout>
<ImageView
android:id="@+id/imgShoot"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="bottom|center"
android:background="@drawable/aperture_closing"/>
</FrameLayout>
请注意,如果父级
FrameLayout
不包含除
标记以外的任何视图,则可以安全地跳过父级布局,直接使用子级布局。每个活动的根目录下都有一个FrameLayout。您在哪个设备上测试此代码?