我如何才能在 android studio 上设置透明背景?
how i i can transparent background on android studio?
我想设计一个与下图完全一样的布局。
当我将我的线性布局 alpha 设置为透明时,其中的所有图标也变得透明并且完全正常。但我想要一种方法让所有项目都具有透明背景!
我想要这样的透明布局:
但我的布局显示如下:
这是我的代码:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:background="@color/colorPrimary"
android:orientation="vertical"
android:alpha="0.5"
>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="1"
>
<RelativeLayout
android:layout_width="1dip"
android:layout_height="fill_parent"
android:layout_weight="0.333"
android:padding="10dp"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@mipmap/consert"
android:layout_gravity="center_horizontal"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="1dip"
android:layout_height="fill_parent"
android:layout_weight="0.333"
android:padding="10dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@mipmap/consert"
android:layout_gravity="center_horizontal"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="1dip"
android:layout_height="fill_parent"
android:layout_weight="0.333"
android:padding="10dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@mipmap/consert"
android:layout_gravity="center_horizontal"
/>
</RelativeLayout>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<RelativeLayout
android:layout_width="1dip"
android:layout_height="fill_parent"
android:layout_weight="0.333">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@mipmap/consert"
android:layout_gravity="center_horizontal"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="1dip"
android:layout_height="fill_parent"
android:layout_weight="0.333">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@mipmap/consert"
android:layout_gravity="center_horizontal"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="1dip"
android:layout_height="fill_parent"
android:layout_weight="0.333">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@mipmap/consert"
android:layout_gravity="center_horizontal"
/>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
如果你想调整透明度,你可以尝试这样改变颜色的alpha我给#55000000你可以改变alpha值(55)任何你想要的。如果你想要黑色透明度,你可以使用#55FFFFFF
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimary"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:background="#55000000"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="3"
>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="10dp"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@mipmap/ic_launcher"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="10dp"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@mipmap/ic_launcher"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="10dp"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@mipmap/ic_launcher"
/>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="3"
>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="10dp"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@mipmap/ic_launcher"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="10dp"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@mipmap/ic_launcher"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="10dp"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@mipmap/ic_launcher"
/>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
透明
android:background="00000000";
黑色透明(你的情况)
android:background="55000000";
这个透明度代码也对我有用:
android:background="@null"
另一方面,对于黑色透明(正如其他人之前回答的那样)
android:background="55000000"
如果您想设置任何颜色的透明度,则可以单击该颜色。 Android 工作室显示两条线 1 用于更改颜色,另一条用于更改透明度,因此您可以从那里调整透明度。
我想设计一个与下图完全一样的布局。
当我将我的线性布局 alpha 设置为透明时,其中的所有图标也变得透明并且完全正常。但我想要一种方法让所有项目都具有透明背景!
我想要这样的透明布局:
但我的布局显示如下:
这是我的代码:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:background="@color/colorPrimary"
android:orientation="vertical"
android:alpha="0.5"
>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="1"
>
<RelativeLayout
android:layout_width="1dip"
android:layout_height="fill_parent"
android:layout_weight="0.333"
android:padding="10dp"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@mipmap/consert"
android:layout_gravity="center_horizontal"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="1dip"
android:layout_height="fill_parent"
android:layout_weight="0.333"
android:padding="10dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@mipmap/consert"
android:layout_gravity="center_horizontal"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="1dip"
android:layout_height="fill_parent"
android:layout_weight="0.333"
android:padding="10dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@mipmap/consert"
android:layout_gravity="center_horizontal"
/>
</RelativeLayout>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<RelativeLayout
android:layout_width="1dip"
android:layout_height="fill_parent"
android:layout_weight="0.333">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@mipmap/consert"
android:layout_gravity="center_horizontal"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="1dip"
android:layout_height="fill_parent"
android:layout_weight="0.333">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@mipmap/consert"
android:layout_gravity="center_horizontal"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="1dip"
android:layout_height="fill_parent"
android:layout_weight="0.333">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@mipmap/consert"
android:layout_gravity="center_horizontal"
/>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
如果你想调整透明度,你可以尝试这样改变颜色的alpha我给#55000000你可以改变alpha值(55)任何你想要的。如果你想要黑色透明度,你可以使用#55FFFFFF
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimary"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:background="#55000000"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="3"
>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="10dp"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@mipmap/ic_launcher"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="10dp"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@mipmap/ic_launcher"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="10dp"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@mipmap/ic_launcher"
/>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="3"
>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="10dp"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@mipmap/ic_launcher"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="10dp"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@mipmap/ic_launcher"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="10dp"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@mipmap/ic_launcher"
/>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
透明
android:background="00000000";
黑色透明(你的情况)
android:background="55000000";
这个透明度代码也对我有用:
android:background="@null"
另一方面,对于黑色透明(正如其他人之前回答的那样)
android:background="55000000"
如果您想设置任何颜色的透明度,则可以单击该颜色。 Android 工作室显示两条线 1 用于更改颜色,另一条用于更改透明度,因此您可以从那里调整透明度。