如何在Android的Z-索引工作,我怎样才能改变顺序后
问题描述:
我有ImageButton的一个XML布局,我想加上“以后”编程一些imageButtons。不幸的是,添加的按钮覆盖了XML按钮。我如何使用zindex? Zindex属性不存在。我想@ + id/btn_surface上。如何在Android的Z-索引工作,我怎样才能改变顺序后
<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>
添加的ImageButton:
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);
感谢所有帮助
答
当您添加childView,largeIcon
在您要使用的ViewGroup.addView(View view, int index)
方法这种情况。这将允许您指定您希望您的意见出现在其中为了
对于你的情况,你可能会想尝试:relativeLayout.addView(largeIcon, 0);
+0
relativeLayout.addView(largeIcon,0);这对我有用!真棒解决方案。谢谢 – Cipo
可能重复[如何通过使用一些整数值设置Z指数( http://stackoverflow.com/questions/8576758/how-to-set-z-index-by-using-some-integer-values) –