Today, when learning to implement the drag effect of moji weather, we can see that we use the rewrite FrameLayout. I flipped through the book and suddenly wondered why FrameLayout was used.
In FrameLayout, in my book, space will never be used up.
Copy codeThe Code is as follows: <? Xml version = "1.0" encoding = "UTF-8"?>
<FrameLayout
Xmlns: android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: background = "#897753"
>
<ImageView
Android: id = "@ + id/image1"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: visibility = "invisible"
Android: src = "@ drawable/sky"/>
<ImageView
Android: id = "@ + id/image2"
Android: visibility = "invisible"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: src = "@ drawable/cloud"/>
<ImageView
Android: id = "@ + id/image3"
Android: visibility = "invisible"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: src = "@ drawable/sun"/>
</FrameLayout>
Image1, image2, and image3 are in the same space. It can be said that they overlap, and the interface displays the recently used one.
They are invisible in my code.
In the overall code, click the screen to change an image.
In addition, I personally feel that the key principle to achieve the drag effect is framelayout, which overlaps several parts of space. The setting is only partially visible. When dragging, set other parts to move.
I found that I needed to deduct ecoins when downloading them. I also pasted the code and changed the picture to my favorite one ~
FramLayoutTestActivity. javaCopy codeThe Code is as follows: import java. util. ArrayList;
Import java. util. List;
Import android. app. Activity;
Import android. OS. Bundle;
Import android. util. Log;
Import android. view. MotionEvent;
Import android. view. View;
Import android. view. animation. Animation;
Import android. widget. ImageView;
Public class FramLayoutTestActivity extends Activity {
Private String TAG = "FramLayoutTestActivity ";
Private ImageView image1;
Private ImageView image2;
Private ImageView image3;
Private List <ImageView> list;
Private int count = 0;
/** Called when the activity is first created .*/
@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );
Image1 = (ImageView) findViewById (R. id. image1 );
Image2 = (ImageView) findViewById (R. id. image2 );
Image3 = (ImageView) findViewById (R. id. image3 );
List = new ArrayList <ImageView> ();
List. add (image1 );
List. add (image2 );
List. add (image3 );
}
@ Override
Public boolean onTouchEvent (MotionEvent event ){
// TODO Auto-generated method stub
If (event. getAction () = MotionEvent. ACTION_DOWN)
{
Log. I (TAG, "move ---");
ShowImage ();
}
Return super. onTouchEvent (event );
}
Private void showImage ()
{
Image1.setVisibility (View. VISIBLE );
Count = count % 3;
For (ImageView I: list)
{
I. setVisibility (View. INVISIBLE );
}
List. get (count). setVisibility (View. VISIBLE );
Count ++;
}
}
Main. xmlCopy codeThe Code is as follows: <? Xml version = "1.0" encoding = "UTF-8"?>
<FrameLayout
Xmlns: android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: background = "#897753"
>
<ImageView
Android: id = "@ + id/image1"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: visibility = "invisible"
Android: src = "@ drawable/sky"/>
<ImageView
Android: id = "@ + id/image2"
Android: visibility = "invisible"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: src = "@ drawable/cloud"/>
<ImageView
Android: id = "@ + id/image3"
Android: visibility = "invisible"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: src = "@ drawable/sun"/>
</FrameLayout>