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

Android移動(dòng)開發(fā)recycleView的頁面點(diǎn)擊跳轉(zhuǎn)設(shè)計(jì)實(shí)現(xiàn)

 更新時(shí)間:2022年05月19日 09:18:32   作者:奮斗中的小宸宸  
這篇文章主要介紹了Android移動(dòng)開發(fā)recycleView的頁面點(diǎn)擊跳轉(zhuǎn)設(shè)計(jì)實(shí)現(xiàn),有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪

一.目的

回顧前兩次的過程和效果以及本次任務(wù)以及最終效果視圖:

(1)第一次實(shí)現(xiàn)界面設(shè)計(jì)和界面跳轉(zhuǎn),示例如下:

(2)第二次是在頁面中設(shè)計(jì)出自己喜歡的布局并加以實(shí)現(xiàn),我實(shí)現(xiàn)的是瀑布流式的布局,如下:

(3)第三次就是這次的任務(wù):Activity頁面跳轉(zhuǎn)(實(shí)現(xiàn)recycleView的頁面進(jìn)行點(diǎn)擊跳轉(zhuǎn)),效果如下:

二.具體代碼和頁面介紹

1.編輯詳情頁面

即點(diǎn)擊后的界面的樣式,代碼以及樣式圖如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".CardInfoActivity">
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >
            <ImageView
                android:id="@+id/card_info_image"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:transitionName="card_info_image"
                tools:srcCompat="@tools:sample/avatars" />
            <TextView
                android:id="@+id/card_info_title"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="TextView"
                android:textSize="30sp" />
        </LinearLayout>
    </ScrollView>
</LinearLayout>

因?yàn)槲业恼麄€(gè)界面是一些好看的圖片,因此我覺得放大圖片更好的觀賞更為重要,在這里同樣運(yùn)用和之前一樣的同比例地放大和縮小圖片的方式,可以根據(jù)自己的具體內(nèi)容進(jìn)行分析。在新的Activity中表現(xiàn)出來

//這個(gè)activity是用來展示對(duì)應(yīng)card信息的activity
public class CardInfoActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_card_info);
        //獲取傳遞來的信息
        ImageView card_info_image=(ImageView) findViewById(R.id.card_info_image);
        TextView card_info_title=(TextView) findViewById(R.id.card_info_title);
        Intent intent=getIntent();
        Bundle bundle=intent.getExtras();
        card_info_image.setImageResource(bundle.getInt("cardImageId"));
        card_info_title.setText(bundle.getString("cardTitle"));
        //修改圖片的高度
        ViewGroup.LayoutParams params = card_info_image.getLayoutParams();
        //TODO 顯然,這高度是由這個(gè)參數(shù)決定的,如果我們知道了寬的大小width,那么我們就能知道實(shí)際縮放比
        //獲取屏幕的寬度
        int screenWidth = ScreenUtil.getScreenWidth(this);
        //Log.d("height",String.valueOf(screenWidth));
        //調(diào)整放入圖片的大小,保證寬一定是屏幕的一半,高度隨著縮放而改變
        float scale = (float)bundle.getInt("height") / (float)bundle.getInt("width");
        params.height =  (int) (screenWidth * scale)+200;
        card_info_image.setLayoutParams(params);
    }
}

2.在原Fragment頁面(首頁)添加點(diǎn)擊跳轉(zhuǎn)功能(我這就是WechatFragment)

//設(shè)置Myadapter的Item監(jiān)聽
        myadapter.setOnRecyclerItemClickListener(new OnRecyclerItemClickListener() {
            @Override
            public void onItemClick(int Position, List<Myadapter.Card> cards) {
                /* 跳轉(zhuǎn)至另一個(gè)activity */
                Intent intent=new Intent(getActivity(),CardInfoActivity.class);
                //傳遞相應(yīng)的參數(shù)
                //我們需要把構(gòu)成一個(gè)圖片的信息傳遞過去
                Bundle bundle=new Bundle();
                bundle.putInt("cardImageId",cards.get(Position).getImageId());
                bundle.putString("cardTitle",cards.get(Position).getTitle());
                bundle.putInt("height",cards.get(Position).getHeight());
                bundle.putInt("width",cards.get(Position).getWidth());
                intent.putExtras(bundle);
                //啟用共享組件的activity過渡
                //所選擇的共享元件,這個(gè)元件是當(dāng)前頁面的元件
                //獲取item的ViewHolder
                Log.d("myposition-firstPo", Arrays.toString(firstStaggeredGridPosition));
                Log.d("myposition-actPo", String.valueOf(Position));
                Log.d("myposition-lastPo", Arrays.toString(lastStaggeredGridPosition));
                //因?yàn)槲沂褂玫氖荢taggeredGridLayoutManager
                RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
                //由于瀑布流是兩列,這里是為了獲得處在頁面的最小值
                int realFirstPosition=Math.min(firstStaggeredGridPosition[0],firstStaggeredGridPosition[1]);
                Myadapter.MyViewHolder viewHolder=(Myadapter.MyViewHolder)recyclerView.getChildViewHolder(recyclerView.getChildAt(Position-realFirstPosition));
                ImageView card_info_image= viewHolder.inserimage;
                ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(getActivity(),
                        Pair.create(card_info_image, "card_info_image"));
                startActivity(intent,options.toBundle());
            }
        });

在Myadapter中設(shè)計(jì)監(jiān)聽接口

//自定義監(jiān)聽接口
interface OnRecyclerItemClickListener {
    //RecyclerView的點(diǎn)擊事件,將信息回調(diào)給view
    void onItemClick(int Position, List<Myadapter.Card> datas);
}

三.倉庫代碼

https://github.com/1224286059/XC_HomeWork1

以上就是Android移動(dòng)開發(fā)recycleView的頁面點(diǎn)擊跳轉(zhuǎn)設(shè)計(jì)實(shí)現(xiàn)的詳細(xì)內(nèi)容,更多關(guān)于recycleView頁面點(diǎn)擊跳轉(zhuǎn)的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評(píng)論