2013-12-12 54 views
0

我写一个相机应用中,我想在底部显示的按钮,同时在纵向视图用户视图的应用程序,并且希望展现给右侧,当使用横向视图横向和纵向视图获取按钮右侧

但在我的应用程序还是我收到按钮右侧,在这两种观点(纵向和横向)

activity_camera.xml: -

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/splash_background" > 

<FrameLayout 
    android:id="@+id/camera_preview" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" 
    android:layout_toLeftOf="@+id/btnView" /> 

<TextView 
    android:id="@+id/angel_title" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:layout_marginTop="18dp" 
    android:layout_toRightOf="@+id/camera_preview" 
    android:maxLines="1" 
    android:visibility="gone" 
    android:textAppearance="?android:attr/textAppearanceSmall" /> 

<Button 
    android:id="@+id/btnView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentTop="true" 
    android:layout_marginTop="50dp" 
    android:background="@drawable/gallery" /> 

<Button 
    android:id="@+id/btnCapture" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerVertical="true" 
    android:layout_toRightOf="@+id/camera_preview" 
    android:background="@drawable/capture" /> 

</RelativeLayout> 

回答

1

你必须提供两种不同的布局文件,一个肖像画d一个用于景观。

具体来说,你应该把你的肖像布局xml到水库/布局和你的景观布局xml到水库/布局土地。请注意,这两个文件必须具有相同的名称。

查看http://developer.android.com/guide/practices/screens_support.html了解更多信息。

+0

好,但我怎么知道哪一个必须显示? – Sun

+0

Android系统决定使用哪一个。这是您的活动在您旋转设备时重新启动的原因之一。 – Ridcully

+1

要将按钮放置在底部,请使用'android:layout_alignParentBottom'。如果你想在底部并排放置,你应该考虑将它们放置在一个水平的LinearLayout中,并使用'android:layout_alignParentBottom'将LinearLayout放置在RelativeLayout的底部。 – Ridcully