kotlin - 2個Fragment實現左右顯示,左邊列表,右邊詳情,平板橫、豎屏切換(一)

kotlin - 2個Fragment實現左右顯示,左邊列表,右邊詳情,平板橫、豎屏切換

(要使用平板測試)平板橫屏:左右fragment實現分屏效果,平板豎屏:只顯示左邊的fragment,點擊才顯示右邊fragment
屏幕旋轉,會銷毀重新創建,執行onCreate方法。
在AndroidManifest.xml配置android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation|keyboardHidden|navigation"屬性,只調用onConfigurationChanged方法
fragment的
add方法
如果新打開一個activity,該fragment只回調onStop()方法,沒有調用onDestroy()方法。
如果popBackStack或者finish,會回調onStop()和onDestroy()方法
?replace方法:舊的fragment執行onDestroy()方法,然后新建一個fragment,執行onViewCreated()方法。

package com.example.androidkotlindemo2.pad.leftrightimport android.content.Intent
import android.content.res.Configuration
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.example.androidkotlindemo2.R
import com.example.androidkotlindemo2.utils.LogUtils/*** Author : wn* Email : maoning20080809@163.com* Date : 2025/8/30 21:41* Description : (要使用平板測試)平板橫屏:左右fragment實現分屏效果,平板豎屏:只顯示左邊的fragment,點擊才顯示右邊fragment* 屏幕旋轉,會銷毀重新創建,執行onCreate方法。* 在AndroidManifest.xml配置android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation|keyboardHidden|navigation"屬性,只調用onConfigurationChanged方法* fragment的* add方法,*  如果新打開一個activity,該fragment只回調onStop()方法,沒有調用onDestroy()方法。*  如果popBackStack或者finish,會回調onStop()和onDestroy()方法* replace:舊的fragment執行onDestroy()方法,然后新建一個fragment,執行onViewCreated()方法。*/
class LRFragmentActivity : AppCompatActivity() {//平板橫屏private var isLandscape: Boolean = falseoverride fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)setContentView(R.layout.lr_fragment_main)LogUtils.d("LeftRightMainActivity onCreate");// 初始化顯示列表Fragmentif (savedInstanceState == null) {supportFragmentManager.beginTransaction().replace(R.id.fragment_list_container, LRListFragment()).commit()}checkOrientation()}//檢查橫、豎屏private fun checkOrientation() {val orientation = resources.configuration.orientationisLandscape = orientation == Configuration.ORIENTATION_LANDSCAPE}fun setOnItemClick(position: Int, lrItem: LRItem) {if(position < 3){if(isLandscape){//平板橫屏,左右顯示fragmentshowItemDetailReplace(lrItem)} else {//平板豎屏,使用新的Activity顯示startRightActivity(lrItem)}} else if(position < 6){//只適配平板橫屏效果showItemDetailAdd(lrItem)} else {showItemNewActivity(lrItem)}}//豎屏打開新的Activityfun startRightActivity(lrItem: LRItem){val intent = Intent(this, LRRightActivity::class.java)intent.putExtra("lr_item", lrItem)startActivity(intent)}//使用replace方法fun showItemDetailReplace(lrItem: LRItem) {val detailFragment = LRDetailReplaceFragment.newInstance(lrItem)supportFragmentManager.beginTransaction().replace(R.id.fragment_detail_container, detailFragment).commit()}//使用add方法, 只回調onStop方法,不回調onDestroy方法fun showItemDetailAdd(LRItem: LRItem) {val detailNewFragment = LRDetailAddFragment.newInstance(LRItem)supportFragmentManager.beginTransaction().add(R.id.fragment_detail_container, detailNewFragment).addToBackStack("detail_new_fragment") // 添加這行才能popBackStack回退.commit()}//屏幕旋轉,移除fragmentfun removeDetailFragment(){val detailFragment = supportFragmentManager.findFragmentById(R.id.fragment_detail_container)if(detailFragment != null){supportFragmentManager.beginTransaction().remove(detailFragment).commit()}}//使用add方法, 只回調onStop方法,不回調onDestroy方法fun showItemNewActivity(LRItem: LRItem) {startActivity(Intent(this, LRNewActivity::class.java))}override fun onConfigurationChanged(newConfig: Configuration) {super.onConfigurationChanged(newConfig)LogUtils.i("LeftRightMainActivity onConfigurationChanged");checkOrientation()removeDetailFragment()}override fun onStop() {super.onStop()LogUtils.d("LeftRightMainActivity onDestroy")}override fun onDestroy() {super.onDestroy()LogUtils.d("LeftRightMainActivity onDestroy")}override fun onNewIntent(intent: Intent?) {super.onNewIntent(intent)LogUtils.i("LeftRightMainActivity onNewIntent")}}

package com.example.androidkotlindemo2.pad.leftrightimport android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.example.androidkotlindemo2.R
import com.example.androidkotlindemo2.utils.LogUtils/*** Author : wn* Email : maoning20080809@163.com* Date : 2025/8/30 21:41* Description :*/
class LRListFragment : Fragment(){private lateinit var recyclerView: RecyclerViewprivate lateinit var adapter: LRAdapterprivate var LRItemList = mutableListOf<LRItem>()override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,savedInstanceState: Bundle?): View? {return inflater.inflate(R.layout.lr_fragment_item_list, container, false)}override fun onViewCreated(view: View, savedInstanceState: Bundle?) {super.onViewCreated(view, savedInstanceState)setupRecyclerView(view)loadItems()}private fun setupRecyclerView(view: View) {recyclerView = view.findViewById(R.id.recycler_view)adapter = LRAdapter(LRItemList, object : LROnItemClickInter{override fun setOnItemClick(position: Int, lrItem: LRItem) {// 通知Activity顯示詳情(activity as? LRFragmentActivity)?.setOnItemClick(position,lrItem)}override fun setOnLongClickListener(position: Int, lrItem: LRItem) {LogUtils.i("長按:${position}")}})recyclerView.layoutManager = LinearLayoutManager(requireContext())recyclerView.adapter = adapterrecyclerView.addItemDecoration(DividerItemDecoration(requireContext(), LinearLayoutManager.VERTICAL))}private fun loadItems() {for(i in 1 .. 20){LRItemList.add(LRItem(i, "項目${i}", "這是第${i}個項目的詳細描述"))}adapter.notifyDataSetChanged()}
}

package com.example.androidkotlindemo2.pad.leftrightimport android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import com.example.androidkotlindemo2.MyApp
import com.example.androidkotlindemo2.R
import com.example.androidkotlindemo2.utils.LogUtils/*** Author : wn* Email : maoning20080809@163.com* Date : 2025/8/30 21:45* Description : 新的詳情,使用fragment的add方法調用,只會調用onStop()*/
class LRDetailAddFragment : Fragment() {companion object {private const val ARG_ITEM = "item"fun newInstance(LRItem: LRItem): LRDetailAddFragment {val fragment = LRDetailAddFragment()val args = Bundle().apply {putParcelable(ARG_ITEM, LRItem)}fragment.arguments = argsreturn fragment}}override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,savedInstanceState: Bundle?): View? {return inflater.inflate(R.layout.lr_fragment_item_detail, container, false)}override fun onViewCreated(view: View, savedInstanceState: Bundle?) {super.onViewCreated(view, savedInstanceState)LogUtils.w("LRDetailAddFragment onViewCreated ----------------------------")LogUtils.w("LRDetailAddFragment onViewCreated()  ${this}")arguments?.getParcelable<LRItem>(ARG_ITEM)?.let { item ->displayItemDetails(view, item)}view.findViewById<Button>(R.id.lr_item_details_back).visibility = View.VISIBLE//返回view.findViewById<Button>(R.id.lr_item_details_back).setOnClickListener {LogUtils.i("LRDetailNewFragment返回")requireActivity().supportFragmentManager.popBackStack()}view.findViewById<Button>(R.id.lr_item_details_finish).visibility = View.VISIBLE//關閉 -view.findViewById<Button>(R.id.lr_item_details_finish).setOnClickListener {LogUtils.i("LRDetailNewFragment關閉")requireActivity().finish()}}override fun onStart() {super.onStart()LogUtils.w("LRDetailAddFragment onStart() ${this}")}override fun onResume() {super.onResume()LogUtils.w("LRDetailAddFragment onResume() ${this}")}override fun onPause() {super.onPause()LogUtils.w("LRDetailAddFragment onPause() ${this}")}override fun onStop() {super.onStop()LogUtils.w("LRDetailAddFragment onStop() ${this}")}override fun onDestroy() {super.onDestroy()LogUtils.w("LRDetailAddFragment onDestroy()  ${this}")}private fun displayItemDetails(view: View, LRItem: LRItem) {view.findViewById<TextView>(R.id.title_text_view).text = LRItem.titleview.findViewById<TextView>(R.id.description_text_view).text = "新頁面:" + LRItem.descriptionview.findViewById<TextView>(R.id.description_text_view).setTextColor(ContextCompat.getColor(MyApp.myApp,R.color.blue))view.findViewById<TextView>(R.id.description_text_view).setTextSize(30f)}
}

package com.example.androidkotlindemo2.pad.leftrightimport android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.TextView
import androidx.fragment.app.Fragment
import com.example.androidkotlindemo2.R
import com.example.androidkotlindemo2.utils.LogUtils/*** Author : wn* Email : maoning20080809@163.com* Date : 2025/8/30 21:45* Description : 使用replace方法,會調用onStop()和onDestroy()方法,*/
class LRDetailReplaceFragment : Fragment() {companion object {private const val ARG_ITEM = "item"fun newInstance(LRItem: LRItem): LRDetailReplaceFragment {val fragment = LRDetailReplaceFragment()val args = Bundle().apply {putParcelable(ARG_ITEM, LRItem)}fragment.arguments = argsreturn fragment}}override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,savedInstanceState: Bundle?): View? {return inflater.inflate(R.layout.lr_fragment_item_detail, container, false)}override fun onViewCreated(view: View, savedInstanceState: Bundle?) {super.onViewCreated(view, savedInstanceState)LogUtils.i("LRDetailReplaceFragment onViewCreated ----------------------------")LogUtils.d("LRDetailReplaceFragment onViewCreated()  ${this}")arguments?.getParcelable<LRItem>(ARG_ITEM)?.let { item ->displayItemDetails(view, item)}//返回view.findViewById<Button>(R.id.lr_item_details_back).visibility = View.GONEview.findViewById<Button>(R.id.lr_item_details_finish).visibility = View.GONE}override fun onStart() {super.onStart()LogUtils.d("LRDetailReplaceFragment onStart()  ${this}")}override fun onResume() {super.onResume()LogUtils.d("LRDetailReplaceFragment onResume()  ${this}")}override fun onPause() {super.onPause()LogUtils.d("LRDetailReplaceFragment onPause()  ${this}")}override fun onStop() {super.onStop()LogUtils.d("LRDetailReplaceFragment onStop()  ${this}")}override fun onDestroy() {super.onDestroy()LogUtils.d("LRDetailReplaceFragment onDestroy()  ${this}")}private fun displayItemDetails(view: View, LRItem: LRItem) {view.findViewById<TextView>(R.id.title_text_view).text = LRItem.titleview.findViewById<TextView>(R.id.description_text_view).text = LRItem.description}
}

package com.example.androidkotlindemo2.pad.leftrightimport android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.TextView
import androidx.cardview.widget.CardView
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import com.example.androidkotlindemo2.MyApp
import com.example.androidkotlindemo2.R/*** Author : wn* Email : maoning20080809@163.com* Date : 2025/8/30 21:42* Description :*/
class LRAdapter(private val itemList: List<LRItem>,private val listener: LROnItemClickInter
) : RecyclerView.Adapter<LRAdapter.ItemViewHolder>() {var selectedPosition = -1inner class ItemViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {val titleTextView: TextView = itemView.findViewById(R.id.title_text_view)val container: LinearLayout = itemView.findViewById(R.id.item_container)}override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder {val view = LayoutInflater.from(parent.context).inflate(R.layout.lr_fragment_item, parent, false)return ItemViewHolder(view)}override fun onBindViewHolder(holder: ItemViewHolder, position: Int) {val lrItem = itemList[position]holder.titleTextView.text = lrItem.titleholder.container.setOnClickListener {listener.setOnItemClick(position, lrItem)selectedPosition = positionnotifyDataSetChanged()}holder.container.setOnLongClickListener {listener.setOnLongClickListener(position, lrItem)true}if(selectedPosition == position){holder.container.setBackgroundColor(ContextCompat.getColor(MyApp.myApp, R.color.lr_item_selected_bg))} else {holder.container.setBackgroundColor(ContextCompat.getColor(MyApp.myApp, R.color.lr_item_default_bg))}}override fun getItemCount(): Int = itemList.size
}

package com.example.androidkotlindemo2.pad.leftrightimport android.os.Bundle
import android.widget.Button
import androidx.appcompat.app.AppCompatActivity
import com.example.androidkotlindemo2.R
import com.example.androidkotlindemo2.utils.LogUtils/*** Author : wn* Email : maoning20080809@163.com* Date : 2025/9/6 13:04* Description : 打開新的頁面*/
class LRNewActivity : AppCompatActivity(){override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)setContentView(R.layout.lr_activity_new)LogUtils.e("LRNewActivity onViewCreated ----------------------------")findViewById<Button>(R.id.lr_activity_new_close).setOnClickListener {finish()}}override fun onCreateDescription(): CharSequence? {return super.onCreateDescription()}override fun onDestroy() {super.onDestroy()LogUtils.e("LRNewActivity onDestroy ----------------------------")}
}

package com.example.androidkotlindemo2.pad.leftright/*** Author : wn* Email : maoning20080809@163.com* Date : 2025/9/6 9:46* Description :*/
interface LROnItemClickInter {//點擊fun setOnItemClick(position: Int, lrItem: LRItem)//長按fun setOnLongClickListener(position: Int, lrItem: LRItem)}

package com.example.androidkotlindemo2.pad.leftrightimport android.os.Bundle
import android.widget.Button
import androidx.appcompat.app.AppCompatActivity
import com.example.androidkotlindemo2.R
import com.example.androidkotlindemo2.utils.LogUtils/*** Author : wn* Email : maoning20080809@163.com* Date : 2025/9/6 13:04* Description : 在Activity中顯示右邊的fragment*/
class LRRightActivity : AppCompatActivity(){override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)setContentView(R.layout.lr_activity_right)val lrItem = intent.getParcelableExtra<LRItem>("lr_item") as LRItemif (savedInstanceState == null) {supportFragmentManager.beginTransaction().replace(R.id.fragment_right_container, LRDetailReplaceFragment.newInstance(lrItem)).commit()}}}

package com.example.androidkotlindemo2.pad.leftrightimport android.os.Parcel
import android.os.Parcelable
/*** Author : wn* Email : maoning20080809@163.com* Date : 2025/8/30 21:41* Description :*/
data class LRItem(val id: Int,val title: String,val description: String,val imageUrl: String? = null
) : Parcelable {constructor(parcel: Parcel) : this(parcel.readInt(),parcel.readString() ?: "",parcel.readString() ?: "",parcel.readString())override fun writeToParcel(parcel: Parcel, flags: Int) {parcel.writeInt(id)parcel.writeString(title)parcel.writeString(description)parcel.writeString(imageUrl)}override fun describeContents(): Int {return 0}companion object CREATOR : Parcelable.Creator<LRItem> {override fun createFromParcel(parcel: Parcel): LRItem {return LRItem(parcel)}override fun newArray(size: Int): Array<LRItem?> {return arrayOfNulls(size)}}
}

lr_fragment_main.xml布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="horizontal"android:weightSum="2"><FrameLayoutandroid:id="@+id/fragment_list_container"android:layout_width="300dp"android:layout_height="match_parent"/><TextViewandroid:layout_width="1dp"android:layout_height="match_parent"android:background="@color/blue"/><FrameLayoutandroid:id="@+id/fragment_detail_container"android:layout_width="match_parent"android:layout_height="match_parent"/></LinearLayout>

lr_fragment_item_list.xml布局
<?xml version="1.0" encoding="utf-8"?>
<androidx.recyclerview.widget.RecyclerViewxmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/recycler_view"android:layout_width="match_parent"android:layout_height="match_parent"android:padding="8dp" />

lr_fragment_item_detail.xml布局
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:background="@color/gray_e5e5e5"android:padding="16dp"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="vertical"><androidx.appcompat.widget.AppCompatButtonandroid:id="@+id/lr_item_details_finish"android:layout_width="wrap_content"android:layout_height="wrap_content"android:textAllCaps="false"android:textSize="30sp"android:textColor="@color/green"android:text="關閉finish"/><androidx.appcompat.widget.AppCompatButtonandroid:id="@+id/lr_item_details_back"android:layout_width="wrap_content"android:layout_height="wrap_content"android:textAllCaps="false"android:textSize="30sp"android:textColor="@color/green"android:text="返回"/><TextViewandroid:id="@+id/title_text_view"android:layout_width="match_parent"android:layout_height="wrap_content"android:textSize="24sp"android:textStyle="bold"android:layout_marginBottom="16dp" /><TextViewandroid:id="@+id/description_text_view"android:layout_width="match_parent"android:layout_height="wrap_content"android:textSize="16sp" /><TextViewandroid:id="@+id/description_tip"android:layout_width="match_parent"android:layout_height="wrap_content"android:textColor="@color/red"android:text="1-3 使用 fragment 的 replace \n 4-6使用 fragment 的add() \n 其他使用打開activity"android:textSize="26sp" /></LinearLayout></ScrollView>

lr_fragment_item.xml布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"android:id="@+id/item_container"android:background="@drawable/lr_click_item_bg"android:clickable="true"android:focusable="true"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_margin="4dp"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:padding="16dp"android:orientation="vertical"><TextViewandroid:id="@+id/title_text_view"android:layout_width="match_parent"android:layout_height="wrap_content"android:textSize="18sp"android:textStyle="bold" /></LinearLayout></LinearLayout>
lr_activity_new.xml布局
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:background="@color/gray_e5e5e5"android:padding="16dp"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="vertical"><androidx.appcompat.widget.AppCompatButtonandroid:id="@+id/lr_activity_new_close"android:layout_width="wrap_content"android:layout_height="wrap_content"android:textAllCaps="false"android:text="關閉"/><TextViewandroid:id="@+id/title_text_view"android:layout_width="match_parent"android:layout_height="wrap_content"android:textSize="24sp"android:textStyle="bold"android:text="新的Activity"android:layout_marginBottom="16dp" /><TextViewandroid:id="@+id/description_text_view"android:layout_width="match_parent"android:layout_height="wrap_content"android:textSize="16sp" /></LinearLayout></ScrollView>

lr_activity_right.xml布局
<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:background="@color/gray_e5e5e5"android:orientation="vertical"><FrameLayoutandroid:id="@+id/fragment_right_container"android:layout_width="match_parent"android:layout_height="match_parent"/>
</LinearLayout>
drawable:
lr_click_item_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"><item android:drawable="@color/lr_item_selected_bg" android:state_selected="true"/><item android:drawable="@color/lr_item_selected_bg" android:state_pressed="true"/><item android:drawable="@color/lr_item_default_bg"/>
</selector>

<color name="lr_item_default_bg">#FFFFFF</color>
<color name="lr_item_selected_bg">#FF00FF</color>
<activity android:name=".pad.leftright.LRFragmentActivity"
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation|keyboardHidden|navigation"/>
<activity android:name=".pad.leftright.LRNewActivity"/>
<activity android:name=".pad.leftright.LRRightActivity"/>

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/921970.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/921970.shtml
英文地址,請注明出處:http://en.pswp.cn/news/921970.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

推薦系統中的AB測試:從設計到分析全流程

推薦系統中的AB測試:從設計到分析全流程 關鍵詞:推薦系統、AB測試、實驗設計、數據分析、效果評估、統計顯著性、用戶體驗 摘要:本文將深入探討推薦系統中AB測試的全流程,從實驗設計到結果分析。我們將用通俗易懂的方式解釋AB測試的核心概念,展示如何科學地評估推薦算法改…

【go語言 | 第1篇】Go環境安裝+go語言特性

文章目錄go開發環境1. 下載安裝包2. 配置環境變量3. GOPROXYgo語言特性1. go的優勢2. go適合做什么3. go缺點編寫一個go程序注&#xff1a;在VSCode中補全go代碼go開發環境 我這里是windows操作系統的環境安裝&#xff0c;其他系統可以查看菜鳥教程&#xff1a;Go 語言環境安裝…

【Pywinauto庫】0. Pywinauto Windows GUI 自動化指南

概述 Pywinauto 是一個用于自動化 Windows GUI 應用程序的 Python 庫&#xff0c;適用于自動化測試、數據錄入和其他重復性桌面操作。 快速參考表方面方法/屬性示例說明安裝pip install pywinauto安裝庫后端選擇Application(backend"uia") 或 Application(backend&qu…

CStringArray 和 CStringList

CStringArray 和 CStringList 都是 MFC 中用于管理字符串集合的類&#xff0c;但它們的內部數據結構和適用場景有顯著差異&#xff0c;選擇時需根據具體操作需求決定。以下從核心區別、功能對比和適用場景三個方面詳細說明&#xff1a;一、核心區別&#xff1a;數據結構決定特性…

2025版基于springboot的企業考勤管理系統

博主介紹&#xff1a;java高級開發&#xff0c;從事互聯網行業六年&#xff0c;熟悉各種主流語言&#xff0c;精通java、python、php、爬蟲、web開發&#xff0c;已經做了多年的設計程序開發&#xff0c;開發過上千套設計程序&#xff0c;沒有什么華麗的語言&#xff0c;只有實…

設計模式(C++)詳解—單例模式(1)

<摘要> 單例模式是創建型設計模式中最經典且應用最廣泛的設計模式之一&#xff0c;它確保一個類只有一個實例并提供全局訪問點。本文從歷史背景和核心概念出發&#xff0c;詳細闡述了單例模式的產生背景和演進歷程&#xff0c;深入剖析了其在資源管理、狀態一致性和訪問控…

將GitHub遠程倉庫修改為ssh

8 將GitHub遠程倉庫修改為ssh 文章目錄8 將GitHub遠程倉庫修改為ssh1 創建本地的ssh密鑰2 設置GitHub密鑰3 將本地庫鏈接到遠程倉庫很多時候在使用GitHub的遠程鏈接使用的是http的格式&#xff0c;但是這個格式并不好&#xff0c;尤其是在代碼上傳的時候&#xff0c;因此需要采…

【OEC-Turbo】網心云 OEC-Turbo 刷機 Armbian 系統教程

前言 大量網心云 OEC 及 OEC-Turbo 設備流入二手市場&#xff08;如海鮮市場&#xff09;&#xff0c;價格低至 70-100 元。相比同配置的拾光塢 N3&#xff08;約 380 元&#xff09;&#xff0c;OEC-Turbo 僅需一個零頭&#xff0c;性價比極高。這些“礦渣”設備外觀與玩客云…

25.線程概念和控制(二)

一、線程周邊問題1.線程的優點創建一個新線程的代價要比創建一個新進程小得多。線程占用的資源要比進程少很多。能充分利用多處理器的可并行數量。在等待慢速I/O操作結束的同時&#xff0c;程序可執行其他的計算任務。計算密集型應用&#xff0c;為了能在多處理器系統上運行&am…

【CVPR2023】奔跑而非行走:追求更高FLOPS以實現更快神經網絡

文章目錄一、論文信息二、論文概要三、實驗動機四、創新之處五、實驗分析六、核心代碼注釋版本七、實驗總結一、論文信息 論文題目&#xff1a;Run, Don’t Walk: Chasing Higher FLOPS for Faster Neural Networks中文題目&#xff1a;奔跑而非行走&#xff1a;追求更高FLOPS…

JVM(二)--- 類加載子系統

目錄 前言 一、類加載過程 1. loading階段 2. Linking階段 2.1 驗證 2.2 準備 2.3 解析 3. Initialization階段 二、類加載器 1. 類加載器的分類 2. 用戶自定義類加載器 三、雙親委派機制 四、其他知識點 前言 JVM的內存結構如圖所示&#xff1a; 一、類加載過程…

Docker 容器的使用

1.容器的基本信息[roothost1 ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 9ac8245b5b08 img-layers-test "python /app/app.py" 45 hours ago Exited (0) 45 hour…

LLMs之Hallucinate:《Why Language Models Hallucinate》的翻譯與解讀

LLMs之Hallucinate&#xff1a;《Why Language Models Hallucinate》的翻譯與解讀 導讀&#xff1a;該論文深入分析了語言模型中幻覺現象的成因&#xff0c;認為幻覺源于預訓練階段的統計壓力和后訓練階段評估體系對猜測行為的獎勵。論文提出了通過修改評估方法&#xff0c;使其…

Spring Cloud @RefreshScope 作用是什么?

RefreshScope 是 Spring Cloud 中的一個重要注解&#xff0c;主要作用如下&#xff1a; 主要功能動態刷新配置 使 Bean 能夠在運行時動態刷新配置屬性當配置中心的配置發生變化時&#xff0c;無需重啟應用即可生效作用域管理 為 Bean 創建一個特殊的作用域 refresh標記的 Bean …

Flutter SDK 安裝與國內鏡像配置全流程(Windows / macOS / Linux)

這是一份面向國內網絡環境的 Flutter 從零到可運行指引&#xff1a;覆蓋 SDK 安裝、平臺依賴準備、國內鏡像配置&#xff08;PUB_HOSTED_URL、FLUTTER_STORAGE_BASE_URL&#xff09;、Android 側 Gradle 倉庫加速&#xff0c;以及 Java/Gradle 版本兼容的關鍵坑位與排查思路。文…

【Java】NIO 簡單介紹

簡介 從 Java 1.4 版本開始引入的一個新的 I/O API&#xff0c;可以替代標準的 Java I/O。提供了與標準 I/O 不同的工作方式&#xff0c;核心是 通道&#xff08;Channel&#xff09;、緩沖區&#xff08;Buffer&#xff09; 和 選擇器&#xff08;Selector&#xff09;。支持非…

Java爬蟲獲取京東item_get_app數據的實戰指南

一、引言京東開放平臺提供了豐富的API接口&#xff0c;其中item_get_app接口可用于獲取商品的詳細信息。這些數據對于市場分析、價格監控、商品推薦等場景具有重要價值。本文將詳細介紹如何使用Java編寫爬蟲&#xff0c;通過調用京東開放平臺的item_get_app接口獲取商品詳情數據…

Vue3源碼reactivity響應式篇之批量更新

概述 在vue3響應式系統設計中&#xff0c;批量更新是優化性能的核心機制之一。當短時間內頻繁多次修改響應式數據時&#xff0c;批量更新可以避免頻繁觸發訂閱者的更新操作&#xff0c;將這些更新操作合并為一次&#xff0c;從而減少不必要的計算和DOM操作。 批量更新也是利用鏈…

AI 模型訓練過程中參數用BF16轉向FP16的原因

大模型訓練從 FP16 轉向 BF16 是一個關鍵的技術演進&#xff0c;其核心原因在于 BF16 在動態范圍和精度之間取得了更優的平衡&#xff0c;從而極大地提升了訓練&#xff08;尤其是大模型訓練&#xff09;的穩定性和有效性。 1. 背景 為什么需要半精度浮點數 (FP16)&#xff1f;…

python網絡爬取個人學習指南-(五)

**************************************************************************************************************author&#xff1a;keyinfodate&#xff1a;2025-09-09 23:50title&#xff1a;網絡信息爬取之多聯級標題內容點擊****************************************…