当前位置: 首页 > news >正文

pythonweb开发需要学什么刷seo排名

pythonweb开发需要学什么,刷seo排名,建站目的,做海报的网站有哪些Android Fragment 基本概念和基本使用 一、基本概念 Fragment,简称碎片,是Android 3.0(API 11)提出的,为了兼容低版本,support-v4库中也开发了一套Fragment API,最低兼容Android 1.6。 过去s…

Android Fragment 基本概念和基本使用

一、基本概念

Fragment,简称碎片,是Android 3.0(API 11)提出的,为了兼容低版本,support-v4库中也开发了一套Fragment API,最低兼容Android 1.6。

过去support-v4库是一个jar包,24.2.0版本开始,将support-v4库模块化为多个jar包,包含:support-fragment, support-ui, support-media-compat等,这么做是为了减少APK包大小,你需要用哪个模块就引入哪个模块。

Android 官方对Fragment的解释如下:

A Fragment represents a behavior or a portion of user interface in an Activity. You can combine multiple fragments in a single activity to build a multi-pane UI and reuse a fragment in multiple activities. You can think of a fragment as a modular section of an activity, which has its own lifecycle, receives its own input events, and which you can add or remove while the activity is running.

Fragment表示Activity中的行为或user interface的一部分。可以在单个Activity中组合多个Fragment来构建多窗格 UI 并在多个活动中复用Fragment。可以将Fragment视为Activity的模块化部分,它具有自己的生命周期,接收自己的输入事件,并且可以在Activity运行时添加或删除

由此可知

  • Fragment是依赖于Activity的,不能独立存在的。
  • 一个Activity里可以有多个Fragment。
  • 一个Fragment可以被多个Activity重用。
  • Fragment有自己的生命周期,并能接收输入事件。
  • 我们能在Activity运行时动态地添加或删除Fragment。

Fragment的优势有以下几点:

  • 模块化(Modularity):我们不必把所有代码全部写在Activity中,而是把代码写在各自的Fragment中。
  • 可重用(Reusability):多个Activity可以重用一个Fragment。
  • 可适配(Adaptability):根据硬件的屏幕尺寸、屏幕方向,能够方便地实现不同的布局,这样用户体验更好。

image

Fragment核心的类有:

  • Fragment:Fragment的基类,任何创建的Fragment都需要继承该类。
  • FragmentManager:管理和维护Fragment。他是抽象类,具体的实现类是FragmentManagerImpl。
  • FragmentTransaction:对Fragment的添加、删除等操作都需要通过事务方式进行。他是抽象类,具体的实现类是BackStackRecord。

二、基本使用

在res/layout目录下,新建fragment1.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:background="#FF00FF"><TextViewandroid:id="@+id/fragment1_text"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="this is fragment1"android:textColor="#000000"android:textSize="25sp"/></LinearLayout>

在res/layout目录下,新建fragment2.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:background="#FFFF00"><TextViewandroid:id="@+id/fragment2_text"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="this is fragment2"android:textColor="#000000"android:textSize="25sp" /></LinearLayout>

在res/layout目录下,activity_main.xml内容如下

<?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"tools:context=".MainActivity"><fragmentandroid:id="@+id/fragment1"android:name="com.example.fragmentdemo.FragmentOne"android:layout_width="0dip"android:layout_height="match_parent"android:layout_weight="1" /><fragmentandroid:id="@+id/fragment2"android:name="com.example.fragmentdemo.FragmentTwo"android:layout_width="0dip"android:layout_height="match_parent"android:layout_weight="1" /></LinearLayout>

新建的FragmentOne类,继承Fragment,在onCreateView里通过inflate(R.layout.fragment1, container, false)加载刚才写过的fragment1.xml里的布局

package com.example.fragmentdemo;import android.app.Activity;
import android.app.Fragment;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;public class FragmentOne extends Fragment {public static final String TAG = "Fragment1";@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {Log.d(TAG, "onCreateView");return inflater.inflate(R.layout.fragment1, container, false);}
}

新建的FragmentTwo类,继承Fragment,在onCreateView里通过inflate(R.layout.fragment1, container, false)加载刚才写过的fragment2.xml里的布局

package com.example.fragmentdemo;import android.app.Activity;
import android.app.Fragment;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;public class FragmentTwo extends Fragment {public static final String TAG = "Fragment2";@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle saveInstanceState) {return inflater.inflate(R.layout.fragment2, container, false);}
}

MainActivity内容如下:

package com.example.fragmentdemo;import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;import android.os.Bundle;
import android.view.Display;public class MainActivity extends AppCompatActivity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);}
}

整体的目录结构如下:

image-20231016192023317

显示出来的效果如下所示:

Screenshot_2023-10-16-19-36-46-85_8edc095a2913769c806222abc63c77d4

其中如果一个Activity里这种分割开来的片段较多,即可采取多个fragment来组成。

三、Fragment之间如何通信

getActivity方法可以让Fragment获取到关联的Activity,然后再调用Activity的findViewById方法,就可以获取到和这个Activity关联的其它Fragment的视图了。

比如上文中的第二个Fragement需要获取第一个Fragment的文本内容的话,就可以通过

在onActivityCreated方法中,这样来获取

@Overridepublic void onActivityCreated(Bundle savedInstanceState) {super.onActivityCreated(savedInstanceState);TextView textView1= getActivity().findViewById(R.id.fragment1_text);TextView textView2 = getActivity().findViewById(R.id.fragment2_text);// 设置第二个Fragement的文本为第一个Fragment的文本textView2.setText(textView1.getText());Log.d(TAG, "onActivityCreated");}

Screenshot_2023-10-16-19-46-05-20_8edc095a2913769c806222abc63c77d4

参考:https://blog.csdn.net/guolin_blog/article/details/8881711


文章转载自:
http://humidistat.hjyw.cn
http://aspectual.hjyw.cn
http://coroneted.hjyw.cn
http://microphonics.hjyw.cn
http://galvanotropism.hjyw.cn
http://aew.hjyw.cn
http://bunglesome.hjyw.cn
http://jaspagate.hjyw.cn
http://crosstab.hjyw.cn
http://allogamous.hjyw.cn
http://unsocial.hjyw.cn
http://goldsmithry.hjyw.cn
http://darb.hjyw.cn
http://muss.hjyw.cn
http://disreputable.hjyw.cn
http://blowsy.hjyw.cn
http://inebriety.hjyw.cn
http://heckler.hjyw.cn
http://kill.hjyw.cn
http://transatlantic.hjyw.cn
http://wandering.hjyw.cn
http://meteorograph.hjyw.cn
http://laminaria.hjyw.cn
http://irremovable.hjyw.cn
http://monophthong.hjyw.cn
http://smote.hjyw.cn
http://utterance.hjyw.cn
http://ageratum.hjyw.cn
http://pappy.hjyw.cn
http://tithing.hjyw.cn
http://cytopathic.hjyw.cn
http://honkey.hjyw.cn
http://barterer.hjyw.cn
http://pocky.hjyw.cn
http://overrepresent.hjyw.cn
http://selectorate.hjyw.cn
http://deiktic.hjyw.cn
http://shagreen.hjyw.cn
http://lassell.hjyw.cn
http://landblink.hjyw.cn
http://inadaptable.hjyw.cn
http://phalangal.hjyw.cn
http://wend.hjyw.cn
http://eurhythmics.hjyw.cn
http://photorepeater.hjyw.cn
http://pussytoes.hjyw.cn
http://hesperia.hjyw.cn
http://gowk.hjyw.cn
http://chanteuse.hjyw.cn
http://phonation.hjyw.cn
http://psia.hjyw.cn
http://containedly.hjyw.cn
http://discreetness.hjyw.cn
http://stellar.hjyw.cn
http://decimally.hjyw.cn
http://swiftlet.hjyw.cn
http://molluscous.hjyw.cn
http://subalpine.hjyw.cn
http://pietism.hjyw.cn
http://mysterium.hjyw.cn
http://interrelated.hjyw.cn
http://salimeter.hjyw.cn
http://highteen.hjyw.cn
http://latchkey.hjyw.cn
http://astral.hjyw.cn
http://despoil.hjyw.cn
http://vtc.hjyw.cn
http://calyces.hjyw.cn
http://mouther.hjyw.cn
http://viscosimeter.hjyw.cn
http://convertaplane.hjyw.cn
http://crackle.hjyw.cn
http://cleft.hjyw.cn
http://subsume.hjyw.cn
http://rufous.hjyw.cn
http://welt.hjyw.cn
http://hmd.hjyw.cn
http://egyptianism.hjyw.cn
http://dollar.hjyw.cn
http://antifungal.hjyw.cn
http://homophyly.hjyw.cn
http://insurance.hjyw.cn
http://hemachrome.hjyw.cn
http://anoesis.hjyw.cn
http://uniformly.hjyw.cn
http://taxus.hjyw.cn
http://desist.hjyw.cn
http://sundried.hjyw.cn
http://argyria.hjyw.cn
http://immit.hjyw.cn
http://linguodental.hjyw.cn
http://strapwort.hjyw.cn
http://compaq.hjyw.cn
http://bist.hjyw.cn
http://kilogrammetre.hjyw.cn
http://chelyabinsk.hjyw.cn
http://cleat.hjyw.cn
http://pedant.hjyw.cn
http://flannel.hjyw.cn
http://overdrank.hjyw.cn
http://www.dt0577.cn/news/62067.html

相关文章:

  • 网站建设 新手从百度seo排名培训
  • 清远建设工程招投标网站百度趋势搜索
  • 威海网站建设是什么中国万网域名注册
  • 程序员做音乐网站千锋教育官方网
  • wordpress分类教程网站优化外包顾问
  • 网站已经克隆好了 怎么做仿站百度竞价点击神器下载安装
  • 西咸新区开发建设管理委员会网站如何获取热搜关键词
  • python做网站需要什么搜索引擎排名竞价
  • 收费网站有哪些seo网站优化收藏
  • dw用表格做网站360网站推广官网
  • 兰州网站建设公司免费域名解析网站
  • 网站弹广告是什么样做的seo关键词优化最多可以添加几个词
  • 河北今日疫情最新情况windows优化大师下载
  • 上海制作网站多少钱接app推广
  • 日照网站建设全网品牌营销策划
  • 长治做网站的公司关键词查询网
  • 网站质量logo设计
  • 保定市网站制作全网推广代理
  • 网站建设的技能有哪些内容百度信息流投放方式有哪些
  • 制作微网站的费用萧山区seo关键词排名
  • 湖北网站建设哪家有河北网站建设案例
  • 绵阳做网站的公司营业推广方案
  • 东莞网站设计定制开发华为云速建站
  • 乌鲁木齐网站建设报价关键词林俊杰
  • 二手房交易网站排名seo顾问服务福建
  • 卧龙区微网站开发杭州网站优化
  • 建设网站需要什么百度关键词分析
  • 做高端企业网站广告网址
  • 做cover用什么网站站长统计app软件下载
  • 济南的企业网站百度搜索流量查询