【问题标题】:How do I make a layout half transparent?如何使布局半透明?
【发布时间】:2016-08-08 23:04:05
【问题描述】:

我正在尝试在容器 main 中创建一个可滚动的选项卡。我正在使图像模糊

但我想显示一半模糊和一半彩色

在第二个中,我想显示模糊背景,另一半显示材料设计颜色“无 alpha”

如何设置 这是我的容器主要代码

<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"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.example.union.front1.MainActivity"
    tools:showIn="@layout/activity_main">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <android.support.v4.view.ViewPager
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/pager"
            android:background="#060606">
            <android.support.v4.view.PagerTitleStrip
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:theme="@style/Base.TextAppearance.AppCompat.Widget.ActionBar.Title"
                android:id="@+id/title"
                android:paddingTop="4dp"
                android:paddingBottom="4dp"
                android:layout_gravity="top"
                android:background="#000"
                style="@style/AppTheme.my"
                android:layout_marginTop="15dp"/>
        </android.support.v4.view.ViewPager>
    </RelativeLayout>
    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="fitXY"
        android:id="@+id/imageView"
        android:alpha="0.8"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true" />

</RelativeLayout>

这是我的片段代码

<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"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context="com.example.union.front1.Album"
    android:background="#e5060606">

    <es.guiguegon.sineview.SineView
        android:id="@+id/sine_view_album"
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        app:sv_sine_alpha="1"
        app:sv_sine_amplitude="25dp"
        app:sv_sine_animation_time_millis="2000"
        app:sv_sine_color="@color/colorPrimaryDark"
        app:sv_sine_periods_to_show="2"
        app:sv_sine_phase="1" />
</RelativeLayout>

如何将布局的一半设置为透明,一半设置为强色

【问题讨论】:

    标签: android android-layout


    【解决方案1】:

    我正在做的错误是我将我的 imageview 放在 viewpager 下方,这意味着图像视图层将超过 view pager 层,所以我将 imageview 层放在 viewpager 层上方,这样我就不必设置 alpha图像,它会在背景中显示图像。当我在片段中使用强烈的颜色时,它会保持强烈,因为我没有使用 alpha 作为图像视图`

    <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"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.example.union.front1.MainActivity"
    tools:showIn="@layout/activity_main">
    <ImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scaleType="fitXY"
    android:id="@+id/imageView"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true" />`
    <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <android.support.v4.view.ViewPager
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/pager"
    
        android:background="#060606"
        >
        <android.support.v4.view.PagerTitleStrip
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:theme="@style/Base.TextAppearance.AppCompat.Widget.ActionBar.Title"
            android:id="@+id/title"
            android:paddingTop="4dp"
            android:paddingBottom="4dp"
            android:layout_gravity="top"
            android:background="#000"
            style="@style/AppTheme.my"
            android:layout_marginTop="15dp"
    
    
            />
    </android.support.v4.view.ViewPager>
    </RelativeLayout>
    </RelativeLayout>
    

    【讨论】:

      猜你喜欢
      • 2013-05-31
      • 2016-02-02
      • 1970-01-01
      • 2011-03-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-13
      • 1970-01-01
      相关资源
      最近更新 更多