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

Android模仿To圈兒個人資料界面層疊淡入淡出顯示效果

 更新時間:2016年07月26日 11:50:56   作者:化作孤島的瓜  
這篇文章主要介紹了Android模仿To圈兒個人資料界面層疊淡入淡出顯示效果的相關(guān)資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下

前幾天做的一個仿To圈個人資料界面的實現(xiàn)效果

下面是To圈的效果Gif圖:

做這個東西其實也花了一下午的時間,一開始思路一直沒理清楚,就開始盲目的去做,結(jié)果反而事倍功半。

以后要吸取教訓(xùn),先詳細(xì)思考清楚其中的邏輯關(guān)系,然后再開始動手寫代碼,這樣比較容易理順。

可以看到實現(xiàn)這個效果還是不難的,得分成以下三個步驟:

1:首先要有一個可拖動的詳細(xì)資料布局(下半部分)。

2:上半部分可跟隨移動。

3:標(biāo)題欄由隱藏到顯示。

涉及到的技術(shù)點有:

1:屏幕像素密度DP轉(zhuǎn)化。

2:自定義視圖的OnTouchListener事件

3:透明度屬性動畫的使用

根據(jù)這三個要求,設(shè)計的布局如下:

userinfo_layout.xml

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@android:color/white"> 
<RelativeLayout 
android:layout_width="match_parent" 
android:layout_height="260dp"> 
<ImageView 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@color/colorTheme"/> 
<LinearLayout 
android:id="@+id/mainheadview" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@drawable/top"></LinearLayout> 
</RelativeLayout> 
<LinearLayout 
android:id="@+id/myscrollLinearlayout" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="#EEEEEE" 
android:clickable="true" 
android:orientation="vertical"> 
<RelativeLayout 
android:layout_width="match_parent" 
android:layout_height="60dp" 
android:background="@android:color/white"> 
<TextView 
android:layout_width="wrap_content" 
android:layout_height="match_parent" 
android:layout_marginLeft="20dp" 
android:gravity="center_vertical" 
android:text="守護天使" 
android:textColor="#DB4E61" 
android:textSize="14sp"/> 
<TextView 
android:layout_width="wrap_content" 
android:layout_height="match_parent" 
android:layout_alignParentTop="true" 
android:layout_marginEnd="66dp" 
android:layout_toStartOf="@+id/imageView" 
android:gravity="center_vertical" 
android:text="暫時沒有守護天使" 
android:textColor="#C0C0C0" 
android:textSize="14sp"/> 
<ImageView 
android:id="@+id/imageView" 
android:layout_width="wrap_content" 
android:layout_height="match_parent" 
android:layout_alignParentEnd="true" 
android:layout_alignParentTop="true" 
android:layout_marginRight="20dp" 
android:paddingBottom="34dp" 
android:paddingTop="34dp" 
android:src="@drawable/ic_more"/> 
</RelativeLayout> 
<View 
android:layout_width="match_parent" 
android:layout_height="1dp" 
android:background="#CCCCCC" 
></View> 
<View 
android:layout_width="match_parent" 
android:layout_height="1dp" 
android:layout_marginTop="15dp" 
android:background="#CCCCCC" 
></View> 
<LinearLayout 
android:layout_width="match_parent" 
android:layout_height="50dp" 
android:background="@android:color/white" 
android:orientation="horizontal"> 
<TextView 
android:layout_width="80dp" 
android:layout_height="match_parent" 
android:layout_marginLeft="15dp" 
android:gravity="center_vertical" 
android:text="昵稱" 
android:textColor="#C0C0C0" 
android:textSize="14sp"/> 
<LinearLayout 
android:layout_width="0dp" 
android:layout_height="match_parent" 
android:layout_marginLeft="10dp" 
android:layout_weight="1" 
android:orientation="vertical" 
> 
<TextView 
android:layout_width="match_parent" 
android:layout_height="0dp" 
android:layout_weight="1" 
android:gravity="center" 
android:textColor="@android:color/black" 
android:textSize="12dp"/> 
<View 
android:layout_width="match_parent" 
android:layout_height="1dp" 
android:background="#CCCCCC" 
></View> 
</LinearLayout> 
</LinearLayout> 
<LinearLayout 
android:layout_width="match_parent" 
android:layout_height="50dp" 
android:background="@android:color/white" 
android:orientation="horizontal"> 
<TextView 
android:layout_width="80dp" 
android:layout_height="match_parent" 
android:layout_marginLeft="15dp" 
android:gravity="center_vertical" 
android:text="個性簽名" 
android:textColor="#C0C0C0" 
android:textSize="14sp"/> 
<TextView 
android:layout_width="0dp" 
android:layout_height="match_parent" 
android:layout_marginLeft="10dp" 
android:layout_weight="1" 
android:background="@android:color/transparent"/> 
</LinearLayout> 
<View 
android:layout_width="match_parent" 
android:layout_height="1dp" 
android:background="#CCCCCC" 
></View> 
<View 
android:layout_width="match_parent" 
android:layout_height="1dp" 
android:layout_marginTop="15dp" 
android:background="#CCCCCC" 
></View> 
<LinearLayout 
android:layout_width="match_parent" 
android:layout_height="100dp" 
android:background="@android:color/white" 
android:orientation="vertical"> 
<TextView 
android:layout_width="match_parent" 
android:layout_height="35dp" 
android:layout_marginLeft="15dp" 
android:gravity="center_vertical" 
android:text="個人相冊" 
android:textColor="#C0C0C0" 
android:textSize="14sp"/> 
<View 
android:layout_width="match_parent" 
android:layout_height="1dp" 
android:background="#CCCCCC" 
></View> 
</LinearLayout> 
<View 
android:layout_width="match_parent" 
android:layout_height="1dp" 
android:background="#CCCCCC" 
></View> 
<View 
android:layout_width="match_parent" 
android:layout_height="1dp" 
android:layout_marginTop="15dp" 
android:background="#CCCCCC" 
></View> 
<LinearLayout 
android:layout_width="match_parent" 
android:layout_height="120dp" 
android:background="@android:color/white" 
android:orientation="vertical"> 
<TextView 
android:layout_width="match_parent" 
android:layout_height="30dp" 
android:layout_marginLeft="15dp" 
android:gravity="center_vertical" 
android:text="私房視頻" 
android:textColor="#DB4E61" 
android:textSize="14sp"/> 
<TextView 
android:layout_width="match_parent" 
android:layout_height="20dp" 
android:layout_marginLeft="15dp" 
android:gravity="start" 
android:text="別人每查看你的一個私房視頻,你講獲得100朵鮮花" 
android:textColor="#C0C0C0" 
android:textSize="10sp"/> 
<View 
android:layout_width="match_parent" 
android:layout_height="1dp" 
android:background="#CCCCCC" 
></View> 
</LinearLayout> 
<View 
android:layout_width="match_parent" 
android:layout_height="1dp" 
android:background="#CCCCCC" 
></View> 
<View 
android:layout_width="match_parent" 
android:layout_height="1dp" 
android:layout_marginTop="15dp" 
android:background="#CCCCCC" 
></View> 
<LinearLayout 
android:layout_width="match_parent" 
android:layout_height="0dp" 
android:layout_weight="1" 
android:background="@android:color/white" 
android:orientation="vertical"> 
<TextView 
android:layout_width="match_parent" 
android:layout_height="35dp" 
android:layout_marginLeft="15dp" 
android:gravity="center_vertical" 
android:text="緣分印象" 
android:textColor="#C0C0C0" 
android:textSize="14sp"/> 
<TextView 
android:layout_width="match_parent" 
android:layout_height="0dp" 
android:layout_weight="1" 
android:gravity="center" 
android:text="Ta還沒有緣分印象" 
android:textColor="#C0C0C0"/> 
</LinearLayout> 
</LinearLayout> 
<RelativeLayout 
android:id="@+id/mainactionbar" 
android:layout_width="match_parent" 
android:layout_height="55dp" 
> 
<ImageView 
android:id="@+id/userinfo_topbar" 
android:visibility="invisible" 
android:background="@color/colorTheme" 
android:layout_width="match_parent" 
android:layout_height="match_parent"/> 
<ImageButton 
android:id="@+id/userinfo_returnbtn" 
style="?android:attr/borderlessButtonStyle" 
android:layout_width="55dp" 
android:layout_height="55dp" 
android:padding="15dp" 
android:scaleType="fitCenter" 
android:src="@drawable/topbar_returnbtn"/> 
</RelativeLayout> 
</RelativeLayout>

該布局由內(nèi)而外嵌套了三層,其中上半部分我直接截了To圈的圖。

android:background="@drawable/top"

代碼實現(xiàn):

package com.whale.nangua.toquan; 
import android.animation.ObjectAnimator; 
import android.app.Activity; 
import android.content.Context; 
import android.os.Bundle; 
import android.support.v7.app.AppCompatActivity; 
import android.util.Log; 
import android.view.MotionEvent; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.ImageView; 
import android.widget.LinearLayout; 
import android.widget.RelativeLayout; 
import android.widget.ScrollView; 
import android.widget.Toast; 
public class MainActivity extends Activity { 
LinearLayout myscrollLinearlayout; 
LinearLayout mainheadview; //頂部個人資料視圖 
RelativeLayout mainactionbar; //頂部菜單欄 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
setContentView(R.layout.userinfo_layout); 
initView(); 
} 
int Y; 
int position = 0; //拖動Linearlayout的距離Y軸的距離 
int scrollviewdistancetotop = 0; //headView的高 
int menubarHeight = 0; 
int chufaHeight = 0; //需要觸發(fā)動畫的高 
float scale; //像素密度 
int headViewPosition = 0; 
ImageView userinfo_topbar; 
static boolean flag = true; 
static boolean topmenuflag = true; 
private void initView() { 
userinfo_topbar = (ImageView) findViewById(R.id.userinfo_topbar); 
//獲得像素密度 
scale = this.getResources().getDisplayMetrics().density; 
mainheadview = (LinearLayout) findViewById(R.id.mainheadview); 
mainactionbar = (RelativeLayout) findViewById(R.id.mainactionbar); 
menubarHeight = (int) (55 * scale); 
chufaHeight = (int) (110 * scale); 
scrollviewdistancetotop = (int) ((260 )*scale); 
position = scrollviewdistancetotop; 
myscrollLinearlayout = (LinearLayout) findViewById(R.id.myscrollLinearlayout); 
myscrollLinearlayout.setY( scrollviewdistancetotop); //要減去Absolote布局距離頂部的高度 
myscrollLinearlayout.setOnClickListener(new View.OnClickListener() { 
@Override 
public void onClick(View v) { 
} 
}); 
myscrollLinearlayout.setOnTouchListener(new View.OnTouchListener() { 
@Override 
public boolean onTouch(View v, MotionEvent event) { 
switch (event.getAction()) { 
case MotionEvent.ACTION_DOWN: 
//按下的Y的位置 
Y = (int) event.getRawY(); 
break; 
case MotionEvent.ACTION_MOVE: 
int nowY = (int) myscrollLinearlayout.getY(); //拖動界面的Y軸位置 
int tempY = (int) (event.getRawY() - Y); //手移動的偏移量 
Y = (int) event.getRawY(); 
if ((nowY + tempY >= 0) && (nowY + tempY <= scrollviewdistancetotop)) { 
if ((nowY + tempY <= menubarHeight)&& (topmenuflag == true) ){ 
userinfo_topbar.setVisibility(View.VISIBLE); 
topmenuflag = false; 
} else if ((nowY + tempY > menubarHeight) && (topmenuflag == flag)) { 
userinfo_topbar.setVisibility(View.INVISIBLE); 
topmenuflag = true; 
} 
int temp = position += tempY; 
myscrollLinearlayout.setY(temp); 
int headviewtemp = headViewPosition += (tempY/5); 
mainheadview.setY(headviewtemp); 
} 
//頂部的動畫效果 
if ((myscrollLinearlayout.getY() <= chufaHeight) && (flag == true)) { 
ObjectAnimator anim = ObjectAnimator.ofFloat(mainheadview, "alpha", 1, 0.0f); 
anim.setDuration(500); 
anim.start(); 
flag = false; 
} else if ((myscrollLinearlayout.getY() > chufaHeight + 40) && (flag == false)) { 
ObjectAnimator anim = ObjectAnimator.ofFloat(mainheadview, "alpha", 0.0f, 1f); 
anim.setDuration(500); 
anim.start(); 
flag = true; 
} 
break; 
} 
return false; 
} 
}); 
} 
}

代碼實現(xiàn)思路:

主要是對以下三個Layout的操作:

LinearLayout myscrollLinearlayout; //底部可拖動的詳細(xì)界面
LinearLayout mainheadview; //頂部個人資料視圖
RelativeLayout mainactionbar; //頂部菜單欄

首先初始化各個布局部分的位置,然后主要是底部拖動布局的動態(tài)事件監(jiān)聽。

需要在這個監(jiān)聽方法中處理與另外兩個布局的交互,這一點比較麻煩,不過代碼里都有詳細(xì)的注釋。

然后這是我實現(xiàn)的效果圖:

可以看到跟To圈的效果幾乎一模一樣哦。

以上所述是小編給大家介紹的Android模仿To圈兒個人資料界面層疊淡入淡出顯示效果,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

  • Android Activity打開后被應(yīng)用快照遮住的問題

    Android Activity打開后被應(yīng)用快照遮住的問題

    這篇文章主要介紹了Android Activity打開后被應(yīng)用快照遮住的問題,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-01-01
  • Android中區(qū)別Drawable Bitmap Canvas Paint

    Android中區(qū)別Drawable Bitmap Canvas Paint

    本文主要介紹Android中Drawable Bitmap Canvas Paint 之間的區(qū)別,這里對這幾個概念做出詳細(xì)介紹,開發(fā)Android游戲的朋友可以參考下
    2016-07-07
  • Android 中SP與DP的區(qū)別實例詳解

    Android 中SP與DP的區(qū)別實例詳解

    這篇文章主要介紹了Android 中SP與DP的區(qū)別實例詳解的相關(guān)資料,需要的朋友可以參考下
    2016-10-10
  • Android實現(xiàn)果凍滑動效果的控件

    Android實現(xiàn)果凍滑動效果的控件

    這篇文章給大家主要介紹了利用Android如何實現(xiàn)果凍效果滑動效果的控件,實現(xiàn)的效果類似于iOS有阻尼效果的滑動控件,一般我們比較親切地稱之為果凍控件,常見的如微信里[我]的那個面板模塊,即使沒有再多的選項,也不會很生硬的不允許用戶滑動。下面來一起看看吧。
    2016-11-11
  • Flutter實現(xiàn)底部導(dǎo)航欄創(chuàng)建詳解

    Flutter實現(xiàn)底部導(dǎo)航欄創(chuàng)建詳解

    ConvexBottomBar是一個底部導(dǎo)航欄組件,用于展現(xiàn)凸起的TAB效果,支持多種內(nèi)置樣式與動畫交互。本文將利用ConvexBottomBar創(chuàng)建漂亮的底部導(dǎo)航欄,感興趣的可以學(xué)習(xí)一下
    2022-01-01
  • Android切面編程知識點詳解

    Android切面編程知識點詳解

    這篇文章給大家整理了關(guān)于Android進階資深開發(fā)必備技能-切面編程的相關(guān)知識點內(nèi)容,有興趣的朋友可以參考學(xué)習(xí)下。
    2018-07-07
  • Android 獲取未安裝的APK圖標(biāo)、版本號、包名等信息方法

    Android 獲取未安裝的APK圖標(biāo)、版本號、包名等信息方法

    下面小編就為大家分享一篇Android 獲取未安裝的APK圖標(biāo)、版本號、包名等信息方法,具有很好的參考價值,希望對大家有所幫助。
    2018-01-01
  • Android compose氣泡升起和水滴下墜動畫實現(xiàn)示例

    Android compose氣泡升起和水滴下墜動畫實現(xiàn)示例

    這篇文章主要為大家介紹了Android compose氣泡升起和水滴下墜動畫實現(xiàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-01-01
  • Android防止按鈕重復(fù)點擊示例代碼

    Android防止按鈕重復(fù)點擊示例代碼

    本文介紹封裝的一個小的工具類庫,按鈕點擊事件類庫,該類庫可以防止按鈕重復(fù)點擊,可以判斷網(wǎng)絡(luò)狀態(tài),可以判斷用戶登錄態(tài),以及自定義驗證條件等等,有興趣的可以了解一下
    2018-05-05
  • Android實現(xiàn)可復(fù)用的篩選頁面

    Android實現(xiàn)可復(fù)用的篩選頁面

    這篇文章主要為大家詳細(xì)介紹了Android實現(xiàn)可復(fù)用的篩選頁面,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-06-06

最新評論