【发布时间】:2016-04-06 12:30:23
【问题描述】:
我有一个 ImageView 作为背景,想在背景前面放置一些小部件。
我尝试了相对布局和线性布局,但仍然发现 AndroidStudio 中的布局预览与我在设备中部署的不一样。设备和背景图片均为 16:9, 1920x1080
- 背景分辨率:1080x1920
- 设备分辨率:1080x1920
- 活动主题:Theme.NoTitleBar.Fullscreen
这是布局 XML 文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.chihangc.imaginecup_prel.MainActivity"
android:layout_margin="0dp"
android:padding="0dp"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/r01_main"
/>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="500dp">
<Button
android:layout_width="210dp"
android:layout_height="80dp"
android:text="New Buttonr"
android:id="@+id/button"
android:layout_marginBottom="127dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:layout_width="210dp"
android:layout_height="80dp"
android:text="New Buttonr"
android:id="@+id/button2"
android:layout_alignTop="@+id/button"
android:layout_toRightOf="@+id/button"
android:layout_toEndOf="@+id/button" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
硬件截图
Android Studio 布局预览
【问题讨论】:
-
您的布局预览中的设备是否与您的硬件设备具有相同的配置?
-
两者是否也在同一个 Android SDK API 版本上?
-
@Pooya,是的,我自己添加的
-
@Radix,谢谢。您能否详细解释一下 Framelayout 如何实现上述解决方案?非常感谢
-
@Elye 是的。我正在使用 API23 Android 6.0
标签: android android-layout android-studio