【问题标题】:Android Change Background Color on Multiple LayoutsAndroid 在多个布局上更改背景颜色
【发布时间】:2014-11-20 21:23:00
【问题描述】:

可视化 XML:http://imgur.com/AgGoVy0

我有一个在相对布局内具有线性布局的 xml。我有一个自定义背景可绘制来设置背景的颜色。但是,我希望主菜单有一个紫色的主体,位于白色的相对布局父级之上。如何将紫色布局堆叠在白色布局之上?

编辑:我通过删除主父相关布局上的背景颜色,然后在自定义可绘制背景菜单中设置紫色颜色来修复它。

<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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".Welcome" 
android:background="#694489"
android:gravity="center">

<LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="10dp"
    android:orientation="vertical" 
    android:background="@drawable/custom_background_menu"
    android:layout_gravity="center"
    >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="30dp"
            android:text="PATHING GAME"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textSize="20dp" 
            android:gravity="center"/>

            <Button
                android:id="@+id/button1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/buttontype"
                android:text="START"
                android:layout_margin="20dp" />

                <Button
                    android:id="@+id/button2"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@drawable/buttontype"
                    android:text="HOW TO PLAY"
                    android:layout_margin="20dp" />

                                    <Button
                    android:id="@+id/button3"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@drawable/buttontype"
                    android:text="EXIT" 
                    android:layout_margin="20dp"/>

</LinearLayout>



</RelativeLayout>

【问题讨论】:

    标签: android android-layout


    【解决方案1】:

    移动

    android:background="@drawable/custom_background_menu"
    

    到一个位于linearLayout1 后面的ImageView,这样主RelativeLayout 将有两个孩子,新的ImageView 和现有的linearLayout1。然后把紫色背景移到linearLayout1,像这样:

    <RelativeLayout ...>
    
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/custom_background_menu"/>
    
        <LinearLayout ...
            android:background="#694489" />
    
    </RelativeLayout>
    

    看看有没有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-22
      • 1970-01-01
      • 2018-09-15
      • 2015-03-29
      • 1970-01-01
      • 2023-03-12
      • 1970-01-01
      • 2014-11-08
      相关资源
      最近更新 更多