我可以通過編程方式設置ImageView的Alpha,而不需要依賴於引入了setAlpha的API級別11?在沒有setAlpha的情況下在ImageView上設置Alpha
回答
ImageView有一個方法setAlpha(int)因爲API水平1.所以你可以在任何API級別使用它。
這是View的setAlpha(float)方法,在API層面推出11
@joynes應該被接受回答 – ruX 2014-01-08 09:36:47
使用'setImageAlpha(X)'SDK版本> = 16! – tipycalFlow 2014-09-28 05:55:07
我認爲最後的評論更有用。 – Vyacheslav 2015-06-13 18:52:28
你可以只用烏爾圖像的新佈局,設置所需佈局的α,將其設置爲覆蓋和膨脹你的時候想。
LayoutInflater inflater = LayoutInflater.from(this);
View overView = inflater.inflate(R.layout.myAlpahImageLayout, null);
this.addContentView(overView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0.5"
tools:context=".MainActivity" >
<ImageView
android:id="@+id/myImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/myImage1" />
</RelativeLayout>
我用代碼來設置圖像本身,而不是視圖的Alpha。這可從API級別1 ..
public void toggleButton(int i) {
if (indImageBtnEnabled[i]) {
int di = getDrawableId(findViewById(myImagebtns[i]));
Drawable d = this.getResources().getDrawable(di);
d.setAlpha(25);
((ImageView) findViewById(myImagebtns[i])).setImageDrawable(d);
indImageBtnEnabled[i] = false;
} else {
// findViewById(myImagebtns[i]).setAlpha(1f) << NEEDS API11;
int di = getDrawableId(findViewById(myImagebtns[i]));
Drawable d = this.getResources().getDrawable(di);
d.setAlpha(255);
((ImageView) findViewById(myImagebtns[i])).setImageDrawable(d);
indImageBtnEnabled[i] = true;
}
}
- 1. 在沒有Outlook的情況下在Windows 7上設置MIME :: Lite
- 2. 如何在沒有約束的情況下設置imageview的高度
- 3. 根據情況設置ImageView
- 4. 使用情況下沒有設置
- 5. 試圖在沒有get/putImageData的情況下在畫布上操作alpha?
- 6. 可以在沒有setter的情況下設置BeanUtils.setProperty()的值嗎?
- 7. 我可以在沒有ADFS的情況下設置SAML IDP嗎?
- 8. 如何在沒有安裝xCode的情況下設置PhoneGap?
- 9. 在沒有腳本的情況下設置VCAP(cloudfoundry)
- 10. 是否可以在沒有cookie的情況下設置nginx?
- 11. 如何在沒有WMSpanel的情況下設置Nimble服務器?
- 12. 我可以在沒有設置ContentLength的情況下創建WebRequest
- 13. 如何在沒有AlertDialog.Builder的情況下設置DialogInterface.OnClickListener?
- 14. 只有在原子集尚未設置的情況下設置
- 15. 在沒有當前上下文的情況下繪製PDFPage
- 16. 如何在沒有SelectionStart的情況下設置TextBox光標位置
- 17. 在沒有複製因子的情況下在cassandra *中設置密鑰空間
- 18. 在沒有eval()的情況下在pymongo中設置mongo數據庫。也許setattr()?
- 19. 在沒有節點的情況下在大型python項目中設置React
- 20. 在沒有設置對象數的情況下在Java中創建數組?
- 21. 在沒有渲染器的情況下在JTable單元格中設置JButton
- 22. 在沒有許可證的情況下在VS2015中導出設置
- 23. 在沒有包裝的情況下在QT上使用OpenGL
- 24. 在沒有YUM的情況下在Centos上安裝MongoDB
- 25. 在沒有迴應的情況下在UIButton上快速點擊
- 26. 如何在沒有Safari的情況下在Windows上運行Webkit?
- 27. 在沒有Ubuntu的情況下在asus chromebook上運行dr racket
- 28. 在沒有安裝python的情況下在Linux上運行python
- 29. 在沒有Flash的情況下在網絡上錄製音頻
- 30. 在沒有任何api的情況下在jquery上傳圖像
喔..還有setAlpha(INT阿爾法),以及在ImageView的多數民衆贊成從API級別工作1 :) – joynes 2012-03-13 21:16:51