2016-04-09 6 views

Antwort

0

Verwenden Sie ein Rahmenlayout. Machen Sie das zweite Bild sichtbar unsichtbar programmgesteuert nach Ihren Anforderungen. (Image2.setVisiblity (View.GONE oder View.VISIBLE))

<FrameLayout android:id="@+id/my_flayout"  
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content"> 
<ImageView 
android:id="@+id/image" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:src="@drawable/sketch" android:layout_alignParentTop="true"/> 
<ImageView 
android:id="@+id/image2" 
android:layout_width="fill_parent" 
android:layout_height="fill_paren" 
android:layout_alignTop="@id/image" 
android:layout_alignLeft="@id/image" 
android:layout_alignRight="@id/image" 
android:layout_alignBottomp="@id/image" 
android:visibility="INVISIBLE"/> 
</FrameLayout> 
0

Sie ein relatives Layout mit zwei Imageview nehmen können, standardmäßig werden sie einander überlappen. nun durch ihre IDs verwenden, können Sie Alpha steuern oder es völlig unsichtbar machen

Ihr Layout sollte so etwas aussehen:

<RelativeLayout 
    android:layout_width = "@dimen/required_width" 
    android:layout_height = "@dimen/required_height"> 
    <ImageView 
     android:id = "@+id/imageview1" 
     android:layout_width = "match_parent" 
     android:layout_height = "match_parent" 
     android:src = "@drawable/your_image_one"/> 
    <ImageView 
     android:id = "@+id/imageview2" 
     android:layout_width = "match_parent" 
     android:layout_height = "match_parent" 
     android:src = "@drawable/your_image_two"/> 
</RelativeLayout> 

jetzt in Java-Code zu tun dies je nach Anforderung:

ImageView imageview_one,imageview_two; 
imageview_one = (ImageView)findViewById(R.id.imageview1); 
imageview_two = (ImageView)findViewById(R.id.imageview2); 
// to hide visibility of imageview_one 
if(imageview_one.getVisibility() == View.VISIBLE){ 
     imageview_one.setVisibility(View.GONE);//or View.INVISIBLE 
     // making imageview2 visible 
     imageview_two.setVisibility(View.VISIBLE); 
}else 
{ 
     imageview_two.setVisibility(View.GONE);//or View.INVISIBLE 
     // making imageview1 visible 
     imageview_one.setVisibility(View.VISIBLE); 
} 

und um ein leichtes Overlay anzuzeigen, können Sie die Transparenz von Bildansichten steuern, indem Sie Folgendes verwenden:

imageview_one.setAlpha(128); //for 50% transparency 0 for 100% transparent and 255 for 100% opaque 

hoffe es hilft ... :)