如何将相对布局背景设置为透明

时间:2018-03-12 14:00:36

标签: android android-layout

我有RelativeLayout ImageButton。我需要在跑步时只显示ImageButton。现在它显示包含RelativeLayout

的按钮
<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"
    android:background="@android:color/transparent"
    tools:context="com.austurn.raksha.raksha.MainActivity">


<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:alpha="0"
        android:background="@android:color/holo_blue_bright" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/transparent">


        <ImageButton
            android:id="@+id/imageButton2"
            android:layout_width="250dp"
            android:layout_height="250dp"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:background="@android:color/transparent"
            android:scaleType="fitCenter"
            app:srcCompat="@drawable/pushme" />
    </RelativeLayout>
</FrameLayout>


</RelativeLayout>

我的屏幕视图

enter image description here

必填屏幕

Required screen-click here

1 个答案:

答案 0 :(得分:0)

如果要在ImageView上显示按钮,请尝试以下操作:

<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"
    android:background="@android:color/transparent"
    tools:context="com.austurn.raksha.raksha.MainActivity">


    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/holo_blue_bright" />


        <ImageButton
            android:id="@+id/imageButton2"
            android:layout_width="250dp"
            android:layout_height="250dp"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:background="@android:color/transparent"
            android:scaleType="fitCenter"
            app:srcCompat="@drawable/pushme" />

</RelativeLayout>
相关问题