亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

基于AnDroid FrameLayout的使用詳解

 更新時間:2013年05月20日 18:01:06   作者:  
本篇文章是對AnDroid FrameLayout的使用進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
今天在學(xué)習(xí)實現(xiàn)墨跡天氣那樣的拖動效果時,看到用的是重寫FrameLayout。翻了翻書,突然想明白,為什么用FrameLayout.
在FrameLayout中,用我看的書中的話說是,空間永遠(yuǎn)用不完。
復(fù)制代碼 代碼如下:

<?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、image3都是在同一塊空間的??梢哉f它們是重疊著的,界面顯示的是最近用的那一個。
在我的代碼中把它們都先不可見。
在整體代碼中實現(xiàn)的是點一下屏幕就換一張圖片。
另外,我個人感覺,實現(xiàn)拖動效果的關(guān)鍵原理就是framelayout使得幾部分空間的重疊。設(shè)置只有一部分可見。當(dāng)拖動時,設(shè)置其他部分移動。
發(fā)現(xiàn)下載附近要扣e幣,我把代碼也貼上,圖片可以換成自己喜歡的~
FramLayoutTestActivity.java
復(fù)制代碼 代碼如下:

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.xml
復(fù)制代碼 代碼如下:

<?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>

相關(guān)文章

  • listview改變字體大小實例講解

    listview改變字體大小實例講解

    點擊字體,字體變大在本教程中將使用listview實現(xiàn),不會不懂的朋友可以參考下哈,希望對你有所幫助
    2013-05-05
  • Android開發(fā)中Activity屬性設(shè)置小結(jié)

    Android開發(fā)中Activity屬性設(shè)置小結(jié)

    Android應(yīng)用開發(fā)中會經(jīng)常遇到Activity組件的使用,下面就來講解下Activity組件。Activity的生命周期、通信方式和IntentFilter等內(nèi)容,并提供了一些日常開發(fā)中經(jīng)常用到的關(guān)于Activity的技巧和方法。通過本文,你可以進(jìn)一步了接Android中Activity的運作方式。
    2015-05-05
  • Android字符串資源文件format方法使用實例

    Android字符串資源文件format方法使用實例

    本文介紹了Android的資源文件values/strings.xml中如何實現(xiàn)格式化字符串,這里舉個簡單的例子供大家參考
    2013-11-11
  • Android中使用Alarm的方法小結(jié)

    Android中使用Alarm的方法小結(jié)

    Alarm是android提供的用于完成鬧鐘式定時任務(wù)的類,系統(tǒng)通過AlarmManager來管理所有的Alarm,下面這篇文章主要給大家介紹了關(guān)于Android中使用Alarm的相關(guān)資料,需要的朋友可以參考下。
    2017-05-05
  • Android 將文件下載到指定目錄的實現(xiàn)代碼

    Android 將文件下載到指定目錄的實現(xiàn)代碼

    本文通過實例代碼給大家介紹了android將文件下載到指定目錄的實現(xiàn)方法,非常不錯,具有參考借鑒價值,需要的的朋友參考下吧
    2017-06-06
  • Android實現(xiàn)電池管理系統(tǒng)

    Android實現(xiàn)電池管理系統(tǒng)

    這篇文章主要為大家詳細(xì)介紹了Android實現(xiàn)電池管理系統(tǒng),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-01-01
  • Android編程中Perferences的用法實例分析

    Android編程中Perferences的用法實例分析

    這篇文章主要介紹了Android編程中Perferences的用法,以實例形式較為詳細(xì)的分析了配置文件preferences.xml的功能、定義及使用方法,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-11-11
  • 安卓GET與POST網(wǎng)絡(luò)請求的三種方式

    安卓GET與POST網(wǎng)絡(luò)請求的三種方式

    今天小編就為大家分享一篇關(guān)于安卓GET與POST網(wǎng)絡(luò)請求的三種方式,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧
    2018-12-12
  • Android入門之利用Spinner實現(xiàn)彈出選擇對話框

    Android入門之利用Spinner實現(xiàn)彈出選擇對話框

    這篇文章主要為大家詳細(xì)介紹了Android里如何巧用Spinner做彈出選擇對話框,文中的示例代碼講解詳細(xì),具有一定的借鑒價值,感興趣的小伙伴可以了解一下
    2022-11-11
  • Android  Activity生命周期和堆棧管理的詳解

    Android Activity生命周期和堆棧管理的詳解

    這篇文章主要介紹了Android Activity生命周期和堆棧管理的詳解的相關(guān)資料,需要的朋友可以參考下
    2017-07-07

最新評論