Bring an imageView to top in framelayout
I have a framelayout in which there is surfaceView and an ImageView, the ImageView being invisible .Based on some event the ImageView has to become visible. But it isnt coming to the foreground. I know the image has become visible as i can see in the logs but its not showing because its not on the top, the SurfaceView is. So how can I bring the ImageView to the top?? Here is my code.
public void onClick(View v) {
if(v.getId() == R.id.Button1) {
Toast.makeText(getApplicationContext(), "Button1", Toast.LENGTH_SHORT).show();
image = (ImageView) findViewById(R.id.lockIcon1);
if(!icon1show) {
icon1show = true;
image.setVisibility(View.VISIBLE);
}else {
icon1show = false;
image.setVisibility(View.INVISIBLE);
}
}else if( v.getId() == R.id.Button2) {
Toast.makeText(getApplicationContext(), "Button2", Toast.LENGTH_SHORT).show();
image = (ImageView) findViewById(R.id.lockIcon2);
if(!icon2show) {
icon2show = true;
image.setVisibility(View.VISIBLE);
}else {
icon2show = false;
image.setVisibility(View.INVISIBLE);
开发者_StackOverflow社区 }
}
}
XML code:
<ImageView android:id="@+id/lockIcon2"
android:src="@drawable/lockicon"
android:visibility = "invisible"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<SurfaceView android:id="@+id/far_end"
android:layout_height="217.33dip" android:layout_width="291dip"/>
</FrameLayout>
Now the image from "lockIcon2" is not showing as there is a SurfaceView along with that imageView in a frameLayout. So please help !!
Please add a snippet of code so we can help you. Do you use the bringToFront()
method?
I didn't understand you fully but I think that you need to put your SurfaceView gone, not invisible. When invisible it will occupy place on screen. Try this...
Found an answer that solved this issue for me using requestTransparentRegion() call.
https://stackoverflow.com/a/8904508/233048
精彩评论