我想要一个基于relativelayout的android UI,如下图所示:
下面是我的布局 xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayoutForPreview"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- surface view that contains camera preview , and seats above @+id/linearLayoutToolbar -->
<SurfaceView
android:id="@+id/surfaceViewBarcodeScanner"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<!-- LinearLayout that contains toolbar that is divided into 3 sections horizontally -->
<LinearLayout
android:id="@+id/linearLayoutToolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/surfaceViewBarcodeScanner"
android:orientation="horizontal" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/scanner_bottom_left" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/scanner_bottom_center_toolbar" />
<ImageView
android:id="@+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/scanner_bottom_right_landscape_button" />
</LinearLayout>
</RelativeLayout>
我使用了Eclipse GUI调色板和我自己的编辑,但是输出不是我所期望的,SurfaceView似乎覆盖了所有屏幕,底部的LinearLayout没有出现。
我在 Galaxy S3 设备上当前结果的快照:
任何帮助将不胜感激,谢谢。
最佳答案
您能否尝试按如下方式修改您的布局:
- 定义 SurfaceView 并将其layout_above 值设置为上一步中创建的线性布局的 ID。将layout_alignParentTop设置为true。
- 定义底部线性布局并将layout_alignParentBottom 设置为true。
仅包含重要部分的智能代码 fragment :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android">
<SurfaceView
android:id="@+id/surfaceViewBarcodeScanner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_above="@+id/linearLayoutToolbar" />
<LinearLayout
android:id="@+id/linearLayoutToolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
</RelativeLayout>
希望这能解决您的问题。
关于java - 无法让所有UI组件出现在RelativeLayout中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19869695/