1

I'm trying to make a layout with a background and add a scroll view at the bottom of this layout.

here's my code:

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);

why I see only the background image?

*Edit:

If I remove all the setBackgroundColor and move the setBackgroundDrawable to the ScrollLayout or the StorageView I see the background on the whole screen

*Edit2:

I edit the code: I remove the unnecessary layouts, and set a background drawable with alpha set to 0, and now it works.

well, I'll be happy if someone explain to me why I need to do this?

piojo
  • 1,919
  • 4
  • 24
  • 40
  • Why are you not writing the layout in the XML editor? Get it looking right in there first and then look at dynamically creating it if you need to. – Ricky Nov 09 '11 at 15:54
  • beacuse StorageView is a customized View that I draw things in its onDraw method. so I cant see it on xml – piojo Nov 09 '11 at 15:59
  • But does the layout above StorageView output correctly? What I mean is get it working before your StorageView. If you have already, then there is no need. :) – Ricky Nov 09 '11 at 16:00
  • as I mentioned in the question if I set the background drawable to the storageView or the scrollLayout, I see it – piojo Nov 09 '11 at 16:03

3 Answers3

2

Try this one:

findViewById(R.id.v).setBackgroundColor(getResources().getColor(android.R.color.transparent));
duggu
  • 37,851
  • 12
  • 116
  • 113
user1384991
  • 2,559
  • 3
  • 17
  • 20
2
<?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>

and then in the manifest

<activity android:name=".SampleActivity" android:theme="@style/Theme.Transparent">
...
</activity>
Md Imran Choudhury
  • 9,343
  • 4
  • 62
  • 60
Lukap
  • 31,523
  • 64
  • 157
  • 244
0

Add the following attribute

android:background="@android:color/transparent"
Otto Kanellis
  • 3,629
  • 1
  • 23
  • 24