我在那裏被擋住了。我試圖在背景上放置透明視圖。 我試過幾種方法。ImageView的透明視圖
throught XML具有:
android:background="@color/transparent"
或
android:color="#80000000"
或把一個參考color.xml文件等等
<resources>
<color name="transp">#80000000</color>
</resources>
我layout.xml這樣
android:background="@color/transp"
我也試圖通過生成的代碼
myView.getBackground().setAlpha(45);
或
myViewm.setBackgroundResource(R.color.trans);
我已經看到了一些相關的帖子做了,但沒有答案的工作。
除此之外更奇怪的是,所有這些解決方案似乎對Eclipse中的GraphicalLayout都很好。 但是,當我啓動我的設備時,屏幕仍然不透明。我在該視圖上畫了一條線以確保發生某些事情;並顯示該行。
這裏是我的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>
和我的代碼
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);
}
和MyView的的onDraw
@Override
protected void onDraw(Canvas canvas)
{
super.onDraw(canvas);
this.setBackgroundResource(R.color.transp);
canvas.drawLine(10,20,30,40, paint);
}
所以,我在哪裏錯了? 謝謝!
男人...你是一個慷慨的真正的!!!! ...這個f *** g的作品!我的錯誤是我想把視圖放在imageView上?爲什麼它不工作?現在,如果我想在這個觀點上畫一些線,我可以通過代碼來實現嗎? – Antoine
@Antoine很高興成功。 「現在,如果我想在這個觀點上畫一些線,我可以通過代碼來實現嗎?」「你必須比這更具體。你想繪製一些在ImageView上預定義的行(意思是:它們在活動開始時顯示)?或者,當你的應用運行時,你是否想繪製自由式(使用觸摸事件)? – Vikram
對不起,因爲含糊不清...我想在活動開始時畫出一些線條,實際上用一些事件監聽器進行拼貼。並解釋爲什麼我自己的解決方案不起作用? – Antoine