使用多个 ImageView 作为背景
Use multiple ImageViews as background
我目前正在为 2 'players' 开发一个应用程序,布局在顶部和(旋转的)底部包含相同的控件。
我使用图像作为背景来为两个玩家显示它:
蓝色代表玩家一,红色代表玩家二。灰色用于设置。
我一直用到现在,但我希望玩家能够更改他们的背景颜色。
我的尝试是将包含选定颜色的 imageView 放在背景中。但是我怎样才能把它们放在后台而不影响我的其他视图呢?我怎样才能添加其中的多个?我想我可以将两个 ImageView 添加到我的 RelativeLayout,第一个从顶部占据父级 space 的 45%,第二个从底部占据。背景本身对于中心来说是灰色的(例如)。
我怎样才能做到这一点?
这个怎么样?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/layout_center"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_centerVertical="true"
android:background="@android:color/darker_gray">
</LinearLayout>
<LinearLayout
android:id="@+id/layout_top"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/layout_center"
android:background="@android:color/holo_red_light">
</LinearLayout>
<LinearLayout
android:id="@+id/layout_bottom"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/layout_center"
android:background="@android:color/holo_blue_light">
</LinearLayout>
</RelativeLayout>
我目前正在为 2 'players' 开发一个应用程序,布局在顶部和(旋转的)底部包含相同的控件。
我使用图像作为背景来为两个玩家显示它:
蓝色代表玩家一,红色代表玩家二。灰色用于设置。 我一直用到现在,但我希望玩家能够更改他们的背景颜色。
我的尝试是将包含选定颜色的 imageView 放在背景中。但是我怎样才能把它们放在后台而不影响我的其他视图呢?我怎样才能添加其中的多个?我想我可以将两个 ImageView 添加到我的 RelativeLayout,第一个从顶部占据父级 space 的 45%,第二个从底部占据。背景本身对于中心来说是灰色的(例如)。
我怎样才能做到这一点?
这个怎么样?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/layout_center"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_centerVertical="true"
android:background="@android:color/darker_gray">
</LinearLayout>
<LinearLayout
android:id="@+id/layout_top"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/layout_center"
android:background="@android:color/holo_red_light">
</LinearLayout>
<LinearLayout
android:id="@+id/layout_bottom"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/layout_center"
android:background="@android:color/holo_blue_light">
</LinearLayout>
</RelativeLayout>