fragment的基本用法-創(chuàng)新互聯(lián)

這篇文章主要講解了“fragment的基本用法”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來(lái)研究和學(xué)習(xí)“fragment的基本用法”吧!

在做網(wǎng)站、成都網(wǎng)站設(shè)計(jì)過(guò)程中,需要針對(duì)客戶(hù)的行業(yè)特點(diǎn)、產(chǎn)品特性、目標(biāo)受眾和市場(chǎng)情況進(jìn)行定位分析,以確定網(wǎng)站的風(fēng)格、色彩、版式、交互等方面的設(shè)計(jì)方向。成都創(chuàng)新互聯(lián)還需要根據(jù)客戶(hù)的需求進(jìn)行功能模塊的開(kāi)發(fā)和設(shè)計(jì),包括內(nèi)容管理、前臺(tái)展示、用戶(hù)權(quán)限管理、數(shù)據(jù)統(tǒng)計(jì)和安全保護(hù)等功能。

fragment 基本使用方法
   1、繼承Fragment類(lèi)或者子類(lèi)并重寫(xiě)
         public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState)
     方法。把xml文件包裹成View對(duì)象,并對(duì)vie進(jìn)行操作,與activity操作View相同。
   2、把fragment添加到activity中:
    1)、在xml中添加,也即靜態(tài)添加:
          <fragment
          android:layout_below="@id/tv"
          android:id="@+id/left_fragment"
          android:name="com.example.test.LeftFragment"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"/>
     2)、在代碼中添加,也即動(dòng)態(tài)添加:
         FragmentManager LeftFragment fragment=new LeftFragment();
         fragmentManager=getFragmentManager();
         FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
         fragmentTransaction.add(R.id.ll, fragment);
         fragmentTransaction.commit();
         注:需要commit().
   3、基本操作,增、刪、改、查。
       重要類(lèi):
        FragmentManager: Fragment管理
        FragmentTransaction:Fragment事務(wù)
        Fragment:具體Fragment
       增:add方法
       刪:remove方法
       改:replace方法
       查:findFragmentByTag 或者 findFragmentById
   4、回退棧
       使用FragmentTransaction中的addToBackStack方法
   5、與activity的通訊
         在Fragment內(nèi)定義一個(gè)接口,其作用是讓activity使用。
      1)、
         public class FragmentB_1 extends Fragment implements OnClickListener {
            private FragmentBIF fragmentBIF;
            public interface FragmentBIF{
               public void setB();
            }
            @Override
            public View onCreateView(LayoutInflater inflater, ViewGroup container,
                  Bundle savedInstanceState) {
               View view = inflater.inflate(R.layout.b, null);
               Button button=(Button) view.findViewById(R.id.but_b);
               button.setOnClickListener(this);
               return view;
            }
            public void setFragmentBIF(FragmentBIF fragmentBIF) {
               this.fragmentBIF = fragmentBIF;
            }
            //button的點(diǎn)擊事件作用到接口的setB方法
            @Override
            public void onClick(View v) {
               if(fragmentBIF!=null){
                  fragmentBIF.setB();
               }
            }
         }
      2)、
         public class FragmentA_1 extends Fragment implements OnClickListener {
         
            private FragmentIF fragmentIF;
            public interface FragmentIF{
               public void setA();
            }
            @Override
            public View onCreateView(LayoutInflater inflater, ViewGroup container,
                  Bundle savedInstanceState) {
               View view = inflater.inflate(R.layout.a, null);
               Button button = (Button) view.findViewById(R.id.but_a);
               button.setOnClickListener(this);
               return view;
            }
            
            //button的點(diǎn)擊事件作用到接口的setA方法上
            @Override
            public void onClick(View v) {
               if(getActivity() instanceof FragmentIF){
                  ((FragmentIF)getActivity()).setA();
               }
            }
         }


感謝各位的閱讀,以上就是“fragment的基本用法”的內(nèi)容了,經(jīng)過(guò)本文的學(xué)習(xí)后,相信大家對(duì)fragment的基本用法這一問(wèn)題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線(xiàn),公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性?xún)r(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專(zhuān)為企業(yè)上云打造定制,能夠滿(mǎn)足用戶(hù)豐富、多元化的應(yīng)用場(chǎng)景需求。

網(wǎng)頁(yè)題目:fragment的基本用法-創(chuàng)新互聯(lián)
網(wǎng)站地址:http://muchs.cn/article2/dpscic.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站建設(shè)、企業(yè)網(wǎng)站制作網(wǎng)站設(shè)計(jì)公司、外貿(mào)建站品牌網(wǎng)站設(shè)計(jì)、動(dòng)態(tài)網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站制作