Вот моя ситуация.Я определил xml-файл с 2 макетами таблиц, каждая из которых имеет 1 строку таблицы, а каждая строка имеет 3 относительных макета, каждый относительный макет имеет 3 представления изображений.
Я хочу понизить альфа на всех видах изображений 1 относительного макетакогда я нажимаю на него, поэтому я использую этот фрагмент кода:
for(int i = 0;i<randStupac.getChildCount();i++)
{
ImageView image =(ImageView)randStupac.getChildAt(i);
image.setAlpha(100);
}
randStupac - это относительная компоновка с 3-мя изображениями, но по какой-то причине это меняет не только эти 3 изображения, но и случайно другие изображения издругие относительные макеты, и я не хочу этого.
я проверил с помощью logcat, что childcount равен 3.
Так что это означает, что в 3 итерации не 3, а случайное число выше 3из ImageViews изменилось.
Так может ли ony1 plz помочь мне изменить только те изображения, которые мне нужно изменить?
вот XML-файл:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" android:paddingBottom="10dp"
android:paddingTop="50dp">
<TableLayout android:layout_height="wrap_content"
android:layout_width="fill_parent" android:id="@+id/TableLayoutTijelo">
<TableRow android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_marginLeft="120dp"
android:id="@+id/TableRowTijelo">
<RelativeLayout android:layout_width="wrap_content"
android:id="@+id/StupacTijelo1" android:layout_height="wrap_content"
android:onClick="clickTijelo">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/SlikaTijelo1" android:src="@drawable/tresnja"></ImageView>
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_below="@+id/SlikaTijelo1" android:id="@+id/SlikaTijelo4" android:src="@drawable/tresnja"></ImageView>
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_below="@+id/SlikaTijelo4"
android:id="@+id/SlikaTijelo7" android:src="@drawable/tresnja"></ImageView>
</RelativeLayout>
<RelativeLayout android:layout_width="wrap_content"
android:id="@+id/StupacTijelo2" android:layout_height="wrap_content"
android:onClick="clickTijelo">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/SlikaTijelo2"
android:src="@drawable/jabuka"></ImageView>
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_below="@+id/SlikaTijelo2" android:id="@+id/SlikaTijelo5" android:src="@drawable/lubenica"></ImageView>
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_below="@+id/SlikaTijelo5"
android:id="@+id/SlikaTijelo8" android:src="@drawable/tresnja"></ImageView>
</RelativeLayout>
<RelativeLayout android:layout_width="wrap_content"
android:id="@+id/StupacTijelo3" android:layout_height="wrap_content"
android:onClick="clickTijelo">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/SlikaTijelo3" android:src="@drawable/lubenica"></ImageView>
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_below="@+id/SlikaTijelo3"
android:id="@+id/SlikaTijelo6" android:src="@drawable/ribizli"></ImageView>
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_below="@+id/SlikaTijelo6"
android:id="@+id/SlikaTijelo9" android:src="@drawable/lubenica"></ImageView>
</RelativeLayout>
</TableRow>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/brojacBod"
android:text="9999999" android:layout_marginTop="50dp"
android:gravity="center" android:layout_marginRight="250dp"
android:layout_marginLeft="7dp"></TextView>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="9999999"
android:id="@+id/brojacPokusaj" android:layout_marginTop="110dp"
android:layout_marginLeft="35dp"></TextView>
</TableLayout>
<TableLayout android:layout_height="wrap_content"
android:layout_alignParentBottom="true" android:layout_width="fill_parent"
android:id="@+id/TableLayoutRandom">
<TableRow android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_marginLeft="120dp"
android:id="@+id/TableRowRandom">
<RelativeLayout android:layout_width="wrap_content"
android:id="@+id/StupacRandom1" android:layout_height="wrap_content"
android:onClick="clickRandom">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:src="@drawable/icon"
android:id="@+id/SlikaRandom1"></ImageView>
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:src="@drawable/icon"
android:layout_below="@+id/SlikaRandom1" android:id="@+id/SlikaRandom4"></ImageView>
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:src="@drawable/icon"
android:layout_below="@+id/SlikaRandom4" android:id="@+id/SlikaRandom7"></ImageView>
</RelativeLayout>
<RelativeLayout android:layout_width="wrap_content"
android:id="@+id/StupacRandom2" android:layout_height="wrap_content"
android:onClick="clickRandom">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/SlikaRandom2" android:src="@drawable/icon"></ImageView>
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:src="@drawable/icon"
android:layout_below="@+id/SlikaRandom2" android:id="@+id/SlikaRandom5"></ImageView>
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:src="@drawable/icon"
android:layout_below="@+id/SlikaRandom5" android:id="@+id/SlikaRandom8"></ImageView>
</RelativeLayout>
<RelativeLayout android:layout_width="wrap_content"
android:id="@+id/StupacRandom3" android:layout_height="wrap_content"
android:onClick="clickRandom">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:src="@drawable/icon"
android:id="@+id/SlikaRandom3"></ImageView>
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:src="@drawable/icon"
android:layout_below="@+id/SlikaRandom3" android:id="@+id/SlikaRandom6"></ImageView>
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:src="@drawable/icon"
android:layout_below="@+id/SlikaRandom6" android:id="@+id/SlikaRandom9"></ImageView>
</RelativeLayout>
</TableRow>
<LinearLayout android:id="@+id/linearLayout1"
android:layout_width="wrap_content" android:layout_height="wrap_content"></LinearLayout>
</TableLayout>
</RelativeLayout>
<ImageView android:layout_width="wrap_content" android:src="@drawable/icon"
android:layout_height="wrap_content" android:layout_marginTop="75dp"
android:id="@+id/comboDouble"></ImageView>
<ImageView android:layout_height="wrap_content"
android:layout_width="wrap_content" android:src="@drawable/icon"
android:layout_marginTop="120dp" android:id="@+id/comboMulti"></ImageView>
<RelativeLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/ReklamaIgra">
</RelativeLayout>
и вот функция «по щелчку»:;
public void clickRandom(final View view)
{
if(odabrano == true)
{
switch(stupacRandom)
{
case 1:randStupac = (RelativeLayout)findViewById(R.id.StupacRandom1);break;
case 2:randStupac = (RelativeLayout)findViewById(R.id.StupacRandom2);break;
case 3:randStupac = (RelativeLayout)findViewById(R.id.StupacRandom3);break;
}
randStupac.startAnimation(animacijaDeselect);
for(int i = 0;i<randStupac.getChildCount();i++)
{
ImageView slika1 =(ImageView)randStupac.getChildAt(i);
slika1.setAlpha(puno);
}
}
switch(view.getId())
{
case R.id.StupacRandom1 :
{
stupacRandom = 1;
randStupac = (RelativeLayout)findViewById(R.id.StupacRandom1);
break;
}
case R.id.StupacRandom2 :
{
stupacRandom = 2;
randStupac = (RelativeLayout)findViewById(R.id.StupacRandom2);
break;
}
case R.id.StupacRandom3 :
{
stupacRandom = 3;
randStupac = (RelativeLayout)findViewById(R.id.StupacRandom3);
break;
}
}
я объявляю RelativeLayout randStupac для всего класса, вы знаете, прежде чем писать функции.
Извините, чтонаписанные мною слова на хорватском