简体   繁体   English

如何在 Android 中的背景图像顶部添加布局

[英]How to add Layout on top of background image in Android

I want to add Linear Layout on top of my background image as shown in below image(that horizontal bars).我想在我的背景图像顶部添加线性布局,如下图所示(水平条)。 在此处输入图片说明

But that is not working.I have checked by adding background color but it didn't shown in the preview.但这不起作用。我已经通过添加背景颜色进行了检查,但它没有显示在预览中。 Below is the way that I had added the Linear Layout.下面是我添加线性布局的方式。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:background="@drawable/back">

    <ImageView
        android:layout_width="200dp"
        android:layout_height="150dp"
        android:src="@drawable/logo_big"
        android:layout_marginLeft="200dp"/>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
    </LinearLayout>

</LinearLayout>

Try using a <RelativeLayout> around your <LinearLayout> .尝试在<LinearLayout>周围使用<RelativeLayout> <LinearLayout> Like this:像这样:

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:background="@drawable/back">

<ImageView
    android:layout_width="200dp"
    android:layout_height="150dp"
    android:src="@drawable/logo_big"
    android:layout_marginLeft="200dp"/>

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
</LinearLayout>

Solution 1:解决方案1:

Set orientation = vertical in your parent LinearLayout.在您的父 LinearLayout 中设置方向 = 垂直。

Solution 2:解决方案2:

Use RelativeLayout for better UI experience.使用 RelativeLayout 以获得更好的 UI 体验。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM