Как работает zindex в андроиде, как потом поменять порядок

У меня есть XML-макет с imageButton, и я хочу программно добавить «позже» некоторые imageButtons. К сожалению, добавленные кнопки закрывают кнопку XML. Как я могу использовать зиндекс? Атрибут Zindex не существует. Я хочу @+id/btn_surface выше.

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="none"
>

<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:scrollbars="none"
    android:fillViewport="false">

    <RelativeLayout
        android:id="@+id/rLayoutss"
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="5000px"
        android:layout_height="fill_parent"
        android:background="@drawable/repeattile"
        tools:context="com.some.asc.somesystems.SomeActivity"
        >

        <ImageView
            android:layout_height="fill_parent"
            android:layout_width="5000px"
            android:id="@+id/iw_pcover"
            android:background="@drawable/repeatovertile"
            android:layout_alignParentTop="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"

            />

        <RelativeLayout
            android:layout_width="800px"
            android:layout_height="480px"
            android:background="@color/gray"
            android:visibility="visible"
            android:id="@+id/rl_all_hud"
            >


        <LinearLayout
                android:layout_width="105px"
                android:layout_height="106px"
                android:visibility="visible"
                android:id="@+id/ll_surface"
                android:orientation="vertical">

                <ImageButton
                    android:layout_width="106px"
                    android:layout_height="105px"
                    android:id="@+id/btn_surface"
                    android:background="@drawable/terr_button_surface"
                    />

                <TextView

                    android:layout_width="94px"
                    android:layout_height="105px"
                    android:id="@+id/tv_surface"
                    android:text="Surface"
                    android:layout_marginLeft="6dp"
                    android:layout_marginTop="-26dp"
                    android:textColor="@android:color/white"
                    android:textSize="14px"
                    android:shadowColor="@android:color/black"
                    android:shadowDx="2"
                    android:shadowDy="2"
                    android:shadowRadius="2"
                    />

            </LinearLayout>
        </RelativeLayout>

    </RelativeLayout>

</HorizontalScrollView>
</ScrollView>

Добавить кнопку изображения:

    RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.rLayoutss);
    ImageButton largeIcon = new ImageButton(context);
    largeIcon.setImageResource(
         getResources().getIdentifier(PObject.getString("imgsrc"), "drawable", getPackageName())
    );
    RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(80,80);
    lp.leftMargin = 100;
    lp.topMargin = 100;
    largeIcon.setLayoutParams(lp);
    largeIcon.setScaleType(ImageView.ScaleType.FIT_CENTER);
    largeIcon.setBackgroundColor(Color.TRANSPARENT);

    relativeLayout.addView(largeIcon);

Спасибо за любую помощь


person Cipo    schedule 04.09.2015    source источник
comment
возможный дубликат Как установить индекс z с помощью некоторого целого числа значения   -  person Gustavo Straube    schedule 04.09.2015


Ответы (1)


Когда вы добавляете свой childView, largeIcon в этом случае вы хотите использовать метод ViewGroup.addView(View view, int index). Это позволит вам указать, в каком порядке вы хотите, чтобы ваши представления отображались.

В вашем случае вы можете попробовать: relativeLayout.addView(largeIcon, 0);

person tambykojak    schedule 04.09.2015
comment
относительныйLayout.addView (большой значок, 0); Это работа для меня! Потрясающее решение. Спасибо - person Cipo; 04.09.2015