【问题标题】:Create semi transparent background image to layout创建半透明背景图像以进行布局
【发布时间】:2018-03-04 09:17:58
【问题描述】:

以图片为例

我想实现一个登录屏幕,我希望用户仅通过 Google plus 登录来登录。我一直在寻找可供选择的设计,但无法理解。但后来我遇到了类似的事情。我试图实现它。

这是我尝试过的。

<?xml version="1.0" encoding="utf-8"?>
<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="com.bt4u.shopcite.login">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:alpha=".5"
        android:background="@drawable/ny"/>

    <ImageView
        android:id="@+id/imageView3"
        android:layout_width="@dimen/_100sdp"
        android:layout_height="@dimen/_100sdp"
        android:layout_centerHorizontal="true"
        app:srcCompat="@drawable/applogo" />

    <com.google.android.gms.common.SignInButton
        android:id="@+id/Sign_in_button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:alpha="1" />
</RelativeLayout>

您可以看到我尝试使用 alpha,但它没有给我相同的结果。我想要图像中显示的克隆类型。

【问题讨论】:

标签: android xml user-interface


【解决方案1】:
<?xml version="1.0" encoding="utf-8"?>
<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="com.bt4u.shopcite.login">

<ImageView
    android:id="@+id/yourbackgroundImageIDD"

    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:srcCompat="@drawable/yourbackgroundImage" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#66000000"">
</LinearLayout>
<ImageView
    android:id="@+id/imageView3"
    android:layout_centerHorizontal="true"
    android:layout_width="@dimen/_100sdp"
    android:layout_height="@dimen/_100sdp"
    app:srcCompat="@drawable/applogo" />
<com.google.android.gms.common.SignInButton
android:id="@+id/Sign_in_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:alpha="1"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
</RelativeLayout>

你可以试试上面的布局。设置背景图像,然后使用背景颜色设置 LinearLayout,并在颜色的十六进制代码中设置 alpha,例如 "#66000000",其中 66alpha,表示黑色。

您可以参考这里的其他 alpha 值:Hex transparency in colors

【讨论】:

  • 这个问题是关于使图像可绘制透明的。我认为您已经强调了背景颜色。
  • 他正在尝试设计像那个屏幕。他误解了 image 是透明的,但实际上 Image 是在透明布局的后面。我的答案是实现那个设计。
  • 是的,我想实现这样的目标。我误解了它就像你想象的那样透明。你也可以帮忙看看按钮吗?
  • 但即使 alpha 值最高,它也不完全相似。还是有点效果的
  • 在示例图像中,它更像是一种图层叠加
猜你喜欢
  • 2011-09-15
  • 1970-01-01
  • 2013-11-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-07-13
相关资源
最近更新 更多