【发布时间】:2015-01-23 07:01:27
【问题描述】:
我有一个覆盖整个屏幕的片段 A 和另一个位于 50dp 屏幕底部的片段 B。片段 B 与片段的一些底部重叠 AI 想让片段 B 半透明,因此片段的重叠部分看到了A。
我尝试使用 Theme.Translucent,使用 framelayouts,使用 setAlpha() 方法,但没有得到想要的结果。就像我们在 android 中有一个半透明的操作栏一样,我想让我的片段 B 半透明。
我尝试参考这些链接... 链接1: making the background translucent
链接 2: https://zaman91.wordpress.com/2010/03/22/android-how-to-create-transparent-or-opeque-background/
链接3: Making a android button’s background translucent,
一些代码可以帮助你理解..
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.examples"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@null"
android:fitsSystemWindows="true" >
<!-- Your normal content view -->
<com.examples.views.SlidingUpPanelLayout
android:id="@+id/sliding_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center|top" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/icn_actionbar_background"
android:minHeight="?attr/actionBarSize" >
<com.examples.views.CustomTextView
android:id="@+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:singleLine="true"
android:text="Toolbar Title"
android:textColor="@color/action_bar_text"
android:textSize="18sp"
android:textStyle="bold"
app:font="@string/font_avenirMedium" />
</android.support.v7.widget.Toolbar>
<!-- Say this is Fragment A -->
<fragment
android:id="@+id/frag_fragmentA"
android:name="com.examples.fragments.FragmentA"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" />
<!-- The rest of your content view -->
</LinearLayout>
<!-- this is fragment B -->
<fragment
android:id="@+id/fragment B"
android:name="com.examples.fragments.MyFragmentB"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center|top" />
</com.examples.SlidingUpPanelLayout>
<LinearLayout
android:layout_width="300dp"
android:layout_height="match_parent"
android:layout_gravity="left|start"
android:fitsSystemWindows="true" >
<!-- Your drawer content -->
<include
android:id="@+id/left_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
layout="@layout/drawer_layout" />
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
SlidingPanelLayout 本身给出了 50dp 的偏移量。所以只有 50dp 的片段 B 是可见的。
在所有这些链接中 Theme.Translucent 被添加到活动主题中..但我想创建一个仅使该片段半透明的主题。
任何建议或帮助家伙..非常感谢。谢谢。
【问题讨论】:
-
getWindow().setBackgroundDrawable(new ColorDrawable(0));??
-
@Skynet...这会让它变成半透明的吗??...还有这个代码行..我需要设置任何主题吗?
-
@AndroidMech 你只想让fragmentA transaculate 吗? fragmentA 上的控件将 b 启用?
-
@user1140237 No..fragment A 应该是原样......在屏幕底部与 Fragment A 重叠的 Fragment B 应该是半透明的......所以 Frag B 后面可以看到 Fragment A 的内容...我本可以发布我想要的图片..但由于一些组织限制..我不能..
-
@Skynet 当我使用你的代码时..它使我的片段 B 完全变黑..我希望片段 A 的布局在片段 B 后面有点可见。
标签: android android-styles translucency