gpt4 book ai didi

java - 我如何通过触摸将 ImageView 置于其他 ImageView 之上(android)

转载 作者:行者123 更新时间:2023-12-02 01:37:46 24 4
gpt4 key购买 nike

它是左边的圆圈unpressed pressed

所以我有imageview =(成形的drawble src),当我触摸它时将drawble res更改为其他所以颜色改变了。但我也想把它放在其他 ImageView 之上,我该怎么做,我尝试 BringToFront 但不起作用,还有其他方法吗?

当我按下一个 ImageView 时,我希望所有 ImageView 都处于其他 ImageView 的前面。

         final ImageView imageView = (ImageView) findViewById(R.id.cir);
imageView.setOnTouchListener(new View.OnTouchListener() {

@Override
public boolean onTouch(View v, MotionEvent event) {
Log.i("IMAGE", "motion event: " + event.toString());
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN: {
imageView.setImageResource(R.drawable.cir_press);
break;

}
case MotionEvent.ACTION_UP: {
imageView.setImageResource(R.drawable.cir);
break;
}
}
return false;
}
});
    <RelativeLayout
android:id="@+id/layoutBottom"
android:layout_width="match_parent"
android:layout_height="356dp"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
android:gravity="bottom|center">


<ImageView
android:id="@+id/cir"
android:elevation="4dp"
android:layout_width="184dp"
android:layout_height="313dp"
android:layout_alignParentBottom="true"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:layout_marginEnd="63dp"
android:layout_marginRight="63dp"
android:layout_marginBottom="43dp"
android:clickable="true"
android:focusable="true"
android:gravity="center"
android:src="@drawable/cir"
/>


<ImageView
android:id="@+id/cir2"
android:layout_width="150dp"
android:layout_height="186dp"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_gravity="center_vertical"
android:layout_marginStart="211dp"
android:layout_marginLeft="211dp"
android:layout_marginTop="38dp"
android:layout_marginBottom="132dp"
android:gravity="center"
android:padding="5dp"
android:src="@drawable/cir2"
/>

<ImageView
android:id="@+id/cir3"
android:layout_width="205dp"
android:layout_height="140dp"
android:layout_alignBottom="@+id/cir2"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="false"
android:layout_marginStart="5dp"
android:layout_marginLeft="5dp"
android:layout_marginEnd="0dp"
android:layout_marginRight="0dp"
android:layout_marginBottom="-127dp"
android:padding="5dp"
android:src="@drawable/cir3" />


</RelativeLayout>


<RelativeLayout
android:id="@+id/layoutTop"
android:layout_width="match_parent"
android:layout_height="231dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="38dp"
android:gravity="bottom">
<ImageView
android:id="@+id/cir4"
android:layout_width="wrap_content"
android:layout_height="212dp"
android:layout_alignWithParentIfMissing="true"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginStart="23dp"
android:layout_marginLeft="23dp"
android:layout_marginEnd="14dp"
android:layout_marginRight="14dp"
android:elevation="10dp"
android:gravity="bottom|center"
android:src="@drawable/cir4"
/>



</RelativeLayout>
</RelativeLayout>

最佳答案

imgView.setVisibility(View.VISIBLE);

imgView.setVisibility(View.INVISIBLE);

imgView.setVisibility(View.GONE);

或者

<小时/>
<ImageView         
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible"
android:src="@drawable/your image" />

关于java - 我如何通过触摸将 ImageView 置于其他 ImageView 之上(android),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54975682/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com