我一直在工作和谷歌搜索一段时间,我似乎很难过。这是我片段的视图:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<include layout="@layout/swipe_hint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"/>
... other views
</RelativeLayout>
布局swipe_hint如下所示:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/swipe_hint_layout"
android:visibility="gone"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
... more views
现在在Java代码中我试图像这样独立地改变alpha:
// this fragment's view is the first xml layout above
View pageOneLayout = fragment.getView();
// get the layout of the swipe hint through the fragment's view since it is included
View swipeView = pageOneLayout.findViewById(R.id.swipe_hint_layout);
// here is where I run into problems
pageOneLayout.setAlpha(.25f);
swipeView.setAlpha(1);
将pageOneLayout
alpha设置为.25会将整个布局的alpha更改为25%透明,这是预期的。但是,当单独设置swipeView
的alpha时,它似乎没有任何效果。 swipeView
仍然是.25透明的。我认为像这样分别设置alpha会导致两个视图具有不同的透明度。然而,这种情况并非如此。那里的任何人都可以对这个问题有所了解吗?
答案 0 :(得分:1)
此行为的原因是RelativeLayout和LinearLayout中的每个子项都从其父级继承alpha。
如果你想拥有单独的alpha级别,请尝试使用FrameLayout。