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

太仓网站建设太仓wordpress 背景音乐

太仓网站建设太仓,wordpress 背景音乐,电商网站设计思维导图,网站建设大概需要多少钱文章目录 主界面布局资源两个工具Fragment主程序 主界面布局资源 在activity_main.xml中#xff0c;声明两个按钮备用#xff0c;再加入一个帧布局#xff0c;待会儿用来展示Fragment。 ?xml version1.0 encodingutf-8? LinearLayo… 文章目录 主界面布局资源两个工具Fragment主程序 主界面布局资源 在activity_main.xml中声明两个按钮备用再加入一个帧布局待会儿用来展示Fragment。 ?xml version1.0 encodingutf-8? LinearLayout xmlns:androidhttp://schemas.android.com/apk/res/androidxmlns:apphttp://schemas.android.com/apk/res-autoxmlns:toolshttp://schemas.android.com/toolsandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:orientationverticaltools:context.MainActivityButtonandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:idid/button1android:textstring/push/Buttonandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:idid/button2android:textstring/replace/FrameLayoutandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:idid/framelayoutandroid:backgroundcolor/purple_200//LinearLayout两个工具Fragment 用来展示的Fragment随便找两个AS预设的即可这里使用的是一个BlankFragment和一个ItemFragment。 BlankFragment ?xml version1.0 encodingutf-8? FrameLayout xmlns:androidhttp://schemas.android.com/apk/res/androidxmlns:toolshttp://schemas.android.com/toolsandroid:layout_widthmatch_parentandroid:layout_heightmatch_parenttools:context.BlankFragment1!-- TODO: Update blank fragment layout --TextViewandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:textstring/hello_blank_fragment //FrameLayoutpackage com.example.dynamicfragment;import android.os.Bundle;import androidx.fragment.app.Fragment;import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup;/*** A simple {link Fragment} subclass.* Use the {link BlankFragment1#newInstance} factory method to* create an instance of this fragment.*/ public class BlankFragment1 extends Fragment {// TODO: Rename parameter arguments, choose names that match// the fragment initialization parameters, e.g. ARG_ITEM_NUMBERprivate static final String ARG_PARAM1 param1;private static final String ARG_PARAM2 param2;// TODO: Rename and change types of parametersprivate String mParam1;private String mParam2;public BlankFragment1() {// Required empty public constructor}/*** Use this factory method to create a new instance of* this fragment using the provided parameters.** param param1 Parameter 1.* param param2 Parameter 2.* return A new instance of fragment BlankFragment1.*/// TODO: Rename and change types and number of parameterspublic static BlankFragment1 newInstance(String param1, String param2) {BlankFragment1 fragment new BlankFragment1();Bundle args new Bundle();args.putString(ARG_PARAM1, param1);args.putString(ARG_PARAM2, param2);fragment.setArguments(args);return fragment;}Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);if (getArguments() ! null) {mParam1 getArguments().getString(ARG_PARAM1);mParam2 getArguments().getString(ARG_PARAM2);}}Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {// Inflate the layout for this fragmentreturn inflater.inflate(R.layout.fragment_blank1, container, false);} }ItemFragment ?xml version1.0 encodingutf-8? androidx.recyclerview.widget.RecyclerView xmlns:androidhttp://schemas.android.com/apk/res/androidxmlns:apphttp://schemas.android.com/apk/res-autoxmlns:toolshttp://schemas.android.com/toolsandroid:idid/listandroid:namecom.example.dynamicfragment.ItemFragmentandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:layout_marginLeft16dpandroid:layout_marginRight16dpapp:layoutManagerLinearLayoutManagertools:context.ItemFragmenttools:listitemlayout/fragment_item /package com.example.dynamicfragment;import android.content.Context; import android.os.Bundle;import androidx.fragment.app.Fragment; import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView;import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup;import com.example.dynamicfragment.placeholder.PlaceholderContent;/*** A fragment representing a list of Items.*/ public class ItemFragment extends Fragment {// TODO: Customize parameter argument namesprivate static final String ARG_COLUMN_COUNT column-count;// TODO: Customize parametersprivate int mColumnCount 1;/*** Mandatory empty constructor for the fragment manager to instantiate the* fragment (e.g. upon screen orientation changes).*/public ItemFragment() {}// TODO: Customize parameter initializationSuppressWarnings(unused)public static ItemFragment newInstance(int columnCount) {ItemFragment fragment new ItemFragment();Bundle args new Bundle();args.putInt(ARG_COLUMN_COUNT, columnCount);fragment.setArguments(args);return fragment;}Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);if (getArguments() ! null) {mColumnCount getArguments().getInt(ARG_COLUMN_COUNT);}}Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {View view inflater.inflate(R.layout.fragment_item_list, container, false);// Set the adapterif (view instanceof RecyclerView) {Context context view.getContext();RecyclerView recyclerView (RecyclerView) view;if (mColumnCount 1) {recyclerView.setLayoutManager(new LinearLayoutManager(context));} else {recyclerView.setLayoutManager(new GridLayoutManager(context, mColumnCount));}recyclerView.setAdapter(new MyItemRecyclerViewAdapter(PlaceholderContent.ITEMS));}return view;} }主程序 在主程序里我们要实现点击按钮显示不同的Fragment。这里使用一种新的实现按钮方式在声明MainActivity类的时候引用View.OnClickListener接口然后在button1.setOnClickListener(this);中传入this这样按钮被点击时就会自动调用后面写的OnClick函数。 在OnClick函数被调用时我们判断是哪一个按钮被点击了然后根据按钮ID将不同的Fragment展现在帧布局上。 package com.example.dynamicfragment;import androidx.appcompat.app.AppCompatActivity; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentTransaction;import android.os.Bundle; import android.view.View; import android.widget.Button;public class MainActivity extends AppCompatActivity implements View.OnClickListener{Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Button button1 findViewById(R.id.button1);Button button2 findViewById(R.id.button2);button1.setOnClickListener(this);button2.setOnClickListener(this);}Overridepublic void onClick(View view) {switch (view.getId()){case R.id.button1:replaceFragment(new BlankFragment1());break;case R.id.button2:replaceFragment(new ItemFragment());break;}}private void replaceFragment(Fragment fragment) {FragmentManager fragmentManager getSupportFragmentManager();FragmentTransaction transaction fragmentManager.beginTransaction();transaction.replace(R.id.framelayout, fragment);//创建replace事件transaction.addToBackStack(null);transaction.commit();//执行transaction中的事件} }还需要重点讲解一下的是replaceFragment函数中的栈transaction.addToBackStack(null);中的null指代的是默认栈。加入该语句后每次更新都会向栈中加入一个Fragment且屏幕上显示的即是栈顶的Fragment。当我们点击返回按钮时栈顶的Fragment被弹出屏幕上显示下一个Fragment。 试验如下交替点击两个按钮若干次屏幕上会依次出现两个Fragment交替覆盖而点击返回按钮后最顶上Fragment则会被撤除。
http://www.hkea.cn/news/14359001/

相关文章:

  • UE做的比较好的网站昆明app开发公司
  • 广德网站建设wordpress x站
  • 哪个做砍价活动的网站好网站制做公司
  • 河北网络公司网站建设进入公众号的欢迎语
  • 北京模板建站哪家好深圳做宣传网站的公司
  • 浙江省建设厅继续教育网站wordpress 视频压缩
  • 怎么购买域名自己做网站网站备案空壳
  • 制作广告网站的步骤网站制作邯郸
  • 娄底建设网站公司wordpress字不能显示
  • 怎么样制作网站教程中国外贸数据网
  • 中劳网做网站成都网站建设设计公司排名
  • 手机壳在线设计网站wordpress 分享微信
  • 网站建设课设总结报告微信营销技巧
  • 网站建设价格西安wordpress 主题图片样式
  • 免费自建商城网站属于网络营销特点的是
  • 专门做产品测评的网站建设项目一次公示网站
  • 福州网站seo优化公司中国建设人才平台网站
  • 合肥做网站 卫来网络wordpress 仿采集
  • wordpress网站速度优化圣耀做单网站
  • 网站功能需求分析文档关键词点击工具
  • 冷饮网站开发背景意义搭建网站是什么专业
  • 邯郸做移动网站多少钱wordpress如何本地安装插件
  • 深圳手机建网站企业做网站的方案
  • 江苏建设造价信息网站平凉网站设计
  • 网站建设-猴王网络给个网站做导航违法吗
  • 网站建设评价指标室内设计学校在哪里
  • asp 网站 源码wordpress 文章加评论
  • 赣州网站建设如何wordpress 评论列表
  • 企业网站导航下拉菜单怎么做网站广告看不到
  • 阿里巴巴1688网站做店铺想开个网站建设的公司