【问题标题】:Landscape and Portrait View getting buttons to Right Side横向和纵向视图将按钮移到右侧
【发布时间】:2013-12-12 11:36:06
【问题描述】:

我正在编写一个相机应用程序,我想在用户以纵向视图查看应用程序时在底部显示按钮,并希望在使用横向视图时显示到右侧

但在我的应用程序中,我仍然在两个视图(纵向和横向)中获得右侧按钮

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>

【问题讨论】:

    标签: android android-layout android-camera


    【解决方案1】:

    您必须提供两种不同的布局文件,一种用于纵向,一种用于横向。

    具体来说,您应该将纵向布局 xml 放入 res/layout,将横向布局 xml 放入 res/layout-land。请注意,这两个文件必须具有相同的名称。

    更多信息请参见http://developer.android.com/guide/practices/screens_support.html

    【讨论】:

    • Android 系统决定使用哪一个。这是每当您旋转设备时您的活动都会重新启动的原因之一。
    • 要将按钮放在底部,请使用android:layout_alignParentBottom。如果您希望两者并排位于底部,则应考虑将它们放入水平 LinearLayout 并使用 android:layout_alignParentBottom 将 LinearLayout 放置在 RelativeLayout 的底部。
    • 我接受了你的回答,但每当我在人像模式下查看相机时:不幸的是应用程序已停止
    • 这与布局的变化有关吗?如果是这样,请将 LogCat 的堆栈跟踪添加到您的问题中。否则,您应该创建一个新问题。
    猜你喜欢
    • 2014-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多