Monday, 19 August 2013

Transparent View over ImageView

Transparent View over ImageView

I'm blocked there. I'm trying to put a transparent View over a background.
I've tried several methods.
throught XML with:
android:background="@color/transparent"
or
android:color="#80000000"
or putting a reference to color.xml file as so
<resources>
<color name="transp">#80000000</color>
</resources>
with my layout.xml like this
android:background="@color/transp"
I've also tried to do it by generated code
myView.getBackground().setAlpha(45);
or
myViewm.setBackgroundResource(R.color.trans);
I've seen some posts related, but none of the answers worked.
Besides which is even stranger is that all of these solutions seems to
wrok fine on the GraphicalLayout in Eclipse. But when I launch my device,
the screen remains not transparent.I've drawn a line on that view to make
sure that something happens; and the line does show.
here is my layout.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".MainActivity" >
<ImageView
android:id="@+id/backgroundview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/space_bg"
android:contentDescription="@string/desc" />
<View
android:id="@+id/tileview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/><!--
android:background="@color/transp"/>-->
</RelativeLayout>
and my code
private ImageView bg;
MyView tV;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
tV = new MyView(this);
setContentView(tV);
}
and the myView onDraw
@Override
protected void onDraw(Canvas canvas)
{
super.onDraw(canvas);
this.setBackgroundResource(R.color.transp);
canvas.drawLine(10,20,30,40, paint);
}
So, where am I wrong? Thanks!!!

No comments:

Post a Comment