2012-03-13 16 views

Trả lời

2

Tôi nghĩ (Nhưng không biết chắc chắn) bạn có thể áp dụng hoạt ảnh alpha cho ImageView của bạn và miễn là fillAfter() được đặt thành true trên hoạt ảnh, Hình ảnh phải ở bất kỳ mức alpha nào kết thúc tại.

+0

Tôi vừa phát hiện ra câu trả lời đơn giản hơn :) .. . xem ở trên. – joynes

+0

đó chắc chắn là cách để đi sau đó – FoamyGuy

40

ImageView có phương thức setAlpha(int) từ API leve 1. Vì vậy, bạn có thể sử dụng nó ở bất kỳ cấp API nào.
Đây là phương pháp setAlpha(float) của View được giới thiệu trong mức API 11.

+3

@joynes Nên được chấp nhận trả lời – ruX

+1

Sử dụng 'setImageAlpha (X)' cho phiên bản SDK> = 16! – tipycalFlow

+0

Tôi nghĩ nhận xét cuối cùng hữu ích hơn nhiều. – Vyacheslav

2

bạn có thể tạo ra một bố cục mới chỉ với hình ảnh ur, thiết lập alpha bạn cần cho việc bố trí, thiết lập nó như một lớp phủ và thổi phồng khi bạn muốn.

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> 
4

Tôi đã sử dụng mã để đặtAlpha của chính hình ảnh chứ không phải chế độ xem. Đây là có sẵn từ cấp 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; 
    } 
} 
Các vấn đề liên quan