Android i ustawienie alpha dla (image) view alpha
Czy naprawdę nie ma odpowiednika atrybutu XML do setAlpha(int)
?
Jeśli nie, Jakie są alternatywy?
9 answers
Nie, Nie ma, zobacz jak brakuje sekcji" Powiązane atrybuty XML " w ImageView .setAlpha (int) dokumentacja. Alternatywą jest użycie widoku .setAlpha (float) którego odpowiednikiem XML jest android:alpha
. Przyjmuje zakres od 0,0 do 1,0 zamiast 0 do 255. Użyj go np. like
<ImageView android:alpha="0.4">
Ten ostatni jest jednak dostępny tylko od poziomu API 11.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-11-09 10:39:13
To łatwiejsze niż druga odpowiedź.
Istnieje wartość xml alpha
, która przyjmuje podwójne wartości.
android:alpha="0.0"
thats invisible
android:alpha="0.5"
see-through
android:alpha="1.0"
Pełna widoczność
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-01-15 18:43:07
Nie jestem pewien co do XML, ale można to zrobić za pomocą kodu w następujący sposób.
ImageView myImageView = new ImageView(this);
myImageView.setAlpha(xxx);
W pre-API 11:
- zakres wynosi od 0 do 255 (włącznie), 0 jest przezroczysty, a 255 jest nieprzezroczysty.
W API 11+:
- zakres wynosi od 0f do 1F (włącznie), 0f jest przezroczysty, a 1f nieprzezroczysty.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-06-28 10:31:55
Być może pomocna alternatywa dla kolorowego tła :
Umieść LinearLayoutnad ImageView i użyjLinearLayout jako filtra nieprzezroczystości. W poniższym małym przykładzie z czarnym tłem:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FF000000" >
<RelativeLayout
android:id="@+id/relativeLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon_stop_big" />
<LinearLayout
android:id="@+id/opacityFilter"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#CC000000"
android:orientation="vertical" >
</LinearLayout>
</RelativeLayout>
Zmień atrybut android: background atrybutu LinearLayout pomiędzy #00000000 (w pełni przezroczysty) i #FF000000 (w pełni nieprzezroczysty).
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-04-23 12:06:39
Istnieje teraz alternatywa XML:
<ImageView
android:id="@+id/example"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/example"
android:alpha="0.7" />
Jest: android: alpha="0.7"
O wartości od 0 (przezroczysty) do 1 (nieprzezroczysty).
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-08-05 18:59:49
Użyj android: alpha=0.5, Aby osiągnąć krycie 50% I zmienić ikony materiałów z Androida z Czarnego na Szary.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-09-16 14:47:47
Użyj tego formularza do starożytnej wersji Androida.
ImageView myImageView;
myImageView = (ImageView) findViewById(R.id.img);
AlphaAnimation alpha = new AlphaAnimation(0.5F, 0.5F);
alpha.setDuration(0);
alpha.setFillAfter(true);
myImageView.startAnimation(alpha);
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-07-30 19:28:26
Alfa może być ustawiona wraz z kolorem używając następującego formatu hex #ARGB lub # AARRGGBB. Zobacz http://developer.android.com/guide/topics/resources/color-list-resource.html
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-02-19 00:47:11
setAlpha(int)
jest przestarzały od API 16
: Android 4.1
Proszę użyć setImageAlpha(int)
zamiast
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-08-23 08:25:43