Android 如何进行布局';s和视图';背景是透明的吗?

Android 如何进行布局';s和视图';背景是透明的吗?,android,layout,view,transparency,Android,Layout,View,Transparency,我正在尝试制作一个带有背景的布局,并在此布局底部添加一个滚动视图 这是我的密码: FrameLayout mainLayout = new FrameLayout(getApplicationContext()); mainLayout.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); mainLayout.setBackgroundResource(R

我正在尝试制作一个带有背景的布局,并在此布局底部添加一个滚动视图

这是我的密码:

FrameLayout mainLayout = new FrameLayout(getApplicationContext());
mainLayout.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
mainLayout.setBackgroundResource(R.drawable.background2);


FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, 200);
params.gravity = Gravity.BOTTOM|Gravity.CENTER;


final ScrollView scrollView = new ScrollView(getApplicationContext());
scrollView.setLayoutParams(params);
scrollView.setBackgroundColor(Color.TRANSPARENT);

StorageView storageView = new StorageView(getApplicationContext());
storageView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

Drawable drawable = getResources().getDrawable(R.drawable.background1);
drawable.setAlpha(0);
storageView.setBackgroundDrawable(drawable);

scrollView.addView(storageView);

mainLayout.addView(scrollView);

setContentView(mainLayout);
为什么我只看到背景图像

*编辑:

如果我删除所有setBackgroundColor并将setBackgroundDrawable移动到ScrollLayout或StorageView,我会在整个屏幕上看到背景

*编辑2:

我编辑代码:我删除了不必要的布局,并将alpha设置为0的背景可绘制,现在它可以工作了

如果有人告诉我为什么我要这么做,我会很高兴的


<?xml version="1.0" encoding="utf-8"?>
<resources>
  <style name="Theme.Transparent" parent="android:Theme">
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:backgroundDimEnabled">false</item>
  </style>
</resources>
真的 @android:彩色/透明 @空的 真的 真的 假的
然后在舱单上

<activity android:name=".SampleActivity" android:theme="@style/Theme.Transparent">
...
</activity>

...
试试这个:

findViewById(R.id.v).setBackgroundColor(getResources().getColor(android.R.color.transparent));

添加以下属性

android:background="@android:color/transparent"

为什么不在XML编辑器中编写布局?首先让它看起来像是在那里,然后如果需要,可以动态创建它。因为StorageView是一个自定义视图,我用它的onDraw方法绘制东西。因此,我无法在XML上看到它,但StorageView上面的布局输出正确吗?我的意思是在StorageView之前让它工作。如果您已经这样做了,那么就没有必要了。:)正如我在问题中提到的,如果我将背景可绘制设置为storageView或scrollLayout,我会看到it@Lukap先生,如何制作碎片??