第二章 UI组件【Android基础学习】

第二章 UI组件【Android基础学习】

  • 前言
  • 版权
  • 推荐
  • 开源
  • 第二章 UI组件
    • 2-1 布局管理器
      • 2-1-1 LinearLayout
      • 2-1-2 RelativeLayout
    • 2-2 TextView
    • 2-3 Button
    • 2-4 EditText
    • 2-5 RadioButton
    • 2-6 复选框CheckBox
    • 2-7 ImageView
    • 2-8 列表视图 ListView
    • 2-9 网格视图 GridView
    • 2-10 滚动视图 ScrollView
    • 2-11-1 RecyclerView (一)
    • 2-11-2 RecyclerView (二)
    • 2-11-3 RecyclerView (三)
    • 2-11-4 RecyclerView (四)
    • 2-12 WebView
  • 最后

前言

以下内容源自《【Android】》
仅供学习交流使用

版权

禁止其他平台发布时删除以下此话
本文首次发布于CSDN平台
作者是CSDN@日星月云
博客主页是https://jsss-1.blog.csdn.net
禁止其他平台发布时删除以上此话

推荐

【天哥】Android开发视频教程最新版 Android Studio开发

图片资源来自:
https://github.com/jinjungle/skypan-yes-code

开源

日星月云 / 安卓基础学习:https://gitee.com/jsss-1/android-basic-learning
jsss-1 / android-basic-learning:https://github.com/jsss-1/android-basic-learning

第二章 UI组件

2-1 布局管理器

LinearLayout:线性布局
RelativeLayout:相对布局

2-1-1 LinearLayout

最常用属性

属性解释
android:idid
android:layout_width宽度
android:layout_height高度
android:layout _margin镶边
android:layout_padding填充
android:orientation排列
android:background背景
<?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=".MainActivity"><LinearLayoutandroid:id="@+id/ll_1"android:layout_width="200dp"android:layout_height="200dp"android:orientation="vertical"android:background="#000000"android:paddingLeft="20dp"android:paddingRight="20dp"android:paddingTop="50dp"android:paddingBottom="10dp"android:layout_marginBottom="20dp"><Viewandroid:layout_width="match_parent"android:layout_height="match_parent"android:background="#FF0033"/></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="200dp"android:background="#0066FF"android:orientation="horizontal"android:layout_marginLeft="15dp"android:layout_marginRight="15dp"><Viewandroid:layout_width="0dp"android:layout_height="match_parent"android:background="#000000"android:layout_weight="1"/><Viewandroid:layout_width="0dp"android:layout_height="match_parent"android:background="#FF0033"android:layout_weight="2"/><Viewandroid:layout_width="0dp"android:layout_height="match_parent"android:background="#55AA99"android:layout_weight="2"/></LinearLayout></LinearLayout>

2-1-2 RelativeLayout

最常用属性

和LinearLayout对比,新增的属性

属性解释
android:layout_toLeftOf在…左边
android:layout_toRightOf在…右边
android:layout_alignBottom和…底部对齐
android:layout alignParentBottom和父空间底部对齐
android:layout_below在…下边
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"><Viewandroid:id="@+id/view_1"android:layout_width="100dp"android:layout_height="100dp"android:background="#000000" /><Viewandroid:id="@+id/view_2"android:layout_width="100dp"android:layout_height="100dp"android:layout_below="@id/view_1"android:background="#FF0033" /><LinearLayoutandroid:id="@+id/ll_1"android:layout_width="match_parent"android:layout_height="200dp"android:layout_below="@id/view_2"android:orientation="horizontal"android:background="#0066FF"android:padding="15dp"><Viewandroid:layout_width="100dp"android:layout_height="match_parent"android:background="#FF0033"/><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:background="#000000"android:padding="15dp"><Viewandroid:id="@+id/view_3"android:layout_width="100dp"android:layout_height="match_parent"android:background="#FF9900" /><Viewandroid:id="@+id/view_4"android:layout_width="100dp"android:layout_height="match_parent"android:background="#FF9900"android:layout_toRightOf="@id/view_3"android:layout_marginLeft="10dp"/></RelativeLayout></LinearLayout></RelativeLayout>

2-2 TextView

  • 文字大小、颜色
  • 显示不下使用…
  • 文字+icon
  • 中划线、下划线
  • 跑马灯
package com.example.helloworld;import androidx.appcompat.app.AppCompatActivity;import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;public class MainActivity extends AppCompatActivity {private Button mBtnTextView;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);mBtnTextView=(Button) findViewById(R.id.btn_textview);mBtnTextView.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {//跳转到TextView演示界面Intent intent=new Intent(MainActivity.this,TextViewActivity.class);startActivity(intent);}});}
}
package com.example.helloworld;import androidx.appcompat.app.AppCompatActivity;import android.annotation.SuppressLint;
import android.graphics.Paint;
import android.os.Bundle;
import android.text.Html;
import android.widget.TextView;public class TextViewActivity extends AppCompatActivity {private TextView mTv4;private TextView mTv5;private TextView mTv6;private TextView mTv7;@SuppressLint("MissingInflatedId")@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_text_view);mTv4 = (TextView) findViewById(R.id.tv_4);mTv4.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);//中划线mTv4.getPaint().setAntiAlias(true);//去除锯齿mTv5 = (TextView) findViewById(R.id.tv_5);mTv5.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);//下划线mTv6 = (TextView) findViewById(R.id.tv_6);mTv6.setText(Html.fromHtml("<u>学习安卓学习安卓</u>"));// android:clickable="true"mTv7 = (TextView) findViewById(R.id.tv_7);mTv7.setSelected(true);}
}
<?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="vertical"android:padding="10dp"><TextViewandroid:id="@+id/tv_1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="学习安卓学习安卓"android:textColor="#000000"android:textSize="24sp" /><TextViewandroid:id="@+id/tv_2"android:layout_width="100dp"android:layout_height="wrap_content"android:maxLines="1"android:ellipsize="end"android:text="学习安卓学习安卓"android:textColor="#000000"android:textSize="24sp"android:layout_marginTop="10dp"/><TextViewandroid:id="@+id/tv_3"android:layout_width="wrap_content"android:layout_height="wrap_content"android:maxLines="1"android:ellipsize="end"android:text="筛选"android:drawableRight="@drawable/icon_arrow_off"android:drawablePadding="5dp"android:textColor="#000000"android:textSize="24sp"android:layout_marginTop="10dp"/><TextViewandroid:id="@+id/tv_4"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="学习安卓学习安卓"android:textColor="#000000"android:textSize="24sp"android:layout_marginTop="10dp"/><TextViewandroid:id="@+id/tv_5"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="学习安卓学习安卓"android:textColor="#000000"android:textSize="24sp"android:layout_marginTop="10dp"/><TextViewandroid:id="@+id/tv_6"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text=""android:textColor="#000000"android:textSize="24sp"android:layout_marginTop="10dp"/><TextViewandroid:id="@+id/tv_7"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="学习安卓学习安卓学习安卓学习安卓学习安卓学习安卓学习安卓学习安卓学习安卓学习安卓学习安卓学习安卓"android:textColor="#000000"android:textSize="24sp"android:singleLine="true"android:ellipsize="marquee"android:marqueeRepeatLimit="marquee_forever"android:focusable="true"android:focusableInTouchMode="true"/>
</LinearLayout>

2-3 Button

  • 文字大小、颜色
  • 自定义背景形状
  • 自定义按压效果
  • 点击事件
package com.example.helloworld;import androidx.appcompat.app.AppCompatActivity;import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;public class MainActivity extends AppCompatActivity {private Button mBtnTextView;private Button mBtnButton;@SuppressLint("MissingInflatedId")@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);mBtnTextView=(Button) findViewById(R.id.btn_textview);mBtnTextView.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {//跳转到TextView演示界面Intent intent=new Intent(MainActivity.this, TextViewActivity.class);startActivity(intent);}});mBtnButton=(Button) findViewById(R.id.btn_button);mBtnButton.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {//跳转到Button演示界面Intent intent=new Intent(MainActivity.this, ButtonActivity.class);startActivity(intent);}});}
}
package com.example.helloworld;import androidx.appcompat.app.AppCompatActivity;import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;public class ButtonActivity extends AppCompatActivity {private Button mBtn3;private TextView mTv1;@SuppressLint("MissingInflatedId")@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_button);mBtn3 = (Button) findViewById(R.id.btn_3);mBtn3.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {Toast.makeText(ButtonActivity.this,"btn3被点击了",Toast.LENGTH_SHORT).show();}});mTv1 = (TextView) findViewById(R.id.tv_1);mTv1.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {Toast.makeText(ButtonActivity.this,"tv1被点击了",Toast.LENGTH_SHORT).show();}});}public void showToast(View view){Toast.makeText(this,"btn4被点击了",Toast.LENGTH_SHORT).show();}}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:padding="15dp"><Buttonandroid:id="@+id/btn_1"android:layout_width="match_parent"android:layout_height="50dp"android:text="按钮1"android:textSize="20sp"android:textColor="#FFFFFF"android:background="#FF0000"></Button><Buttonandroid:id="@+id/btn_2"android:layout_width="match_parent"android:layout_height="50dp"android:text="按钮2"android:textSize="20sp"android:textColor="#FFFFFF"android:background="@drawable/bg_btn2"android:layout_below="@+id/btn_1"android:layout_marginTop="10dp"/><Buttonandroid:id="@+id/btn_3"android:layout_width="match_parent"android:layout_height="50dp"android:text="按钮3"android:textSize="20sp"android:textColor="#FF9900"android:background="@drawable/bg_btn3"android:layout_below="@+id/btn_2"android:layout_marginTop="10dp"/><Buttonandroid:id="@+id/btn_4"android:layout_width="match_parent"android:layout_height="50dp"android:text="按钮4"android:textSize="20sp"android:textColor="#FFFFFF"android:background="@drawable/bg_btn4"android:layout_below="@+id/btn_3"android:onClick="showToast"android:layout_marginTop="10dp"></Button><TextViewandroid:id="@+id/tv_1"android:layout_width="match_parent"android:layout_height="50dp"android:textColor="#000000"android:textSize="20sp"android:text="文字1"android:layout_below="@id/btn_4"android:layout_marginTop="10dp"android:background="#FFAD33"android:gravity="center"/></RelativeLayout>

2-4 EditText

  • 常用属性
  • 监听事件
  • 制作登录界面

2-5 RadioButton

  • 常用属性
  • 自定义样式
  • 监听事件

2024-6-3 00:45:01

2-6 复选框CheckBox

2024-6-3 15:39:16

  • 常用属性
  • 自定义样式
  • 监听事件
package com.example.helloworld;import androidx.appcompat.app.AppCompatActivity;import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.Toast;public class CheckBoxActivity extends AppCompatActivity {private CheckBox mCb5, mCb6;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_check_box);mCb5 = (CheckBox) findViewById(R.id.cb_5);mCb6 = (CheckBox) findViewById(R.id.cb_6);mCb5.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(CompoundButton compoundButton, boolean b) {Toast.makeText(CheckBoxActivity.this,b?"5选中":"5未选中",Toast.LENGTH_SHORT).show();}});mCb6.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(CompoundButton compoundButton, boolean b) {Toast.makeText(CheckBoxActivity.this,b?"6选中":"6未选中",Toast.LENGTH_SHORT).show();}});}
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:padding="15dp"><TextViewandroid:id="@+id/tv_title"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="你会哪些移动开发:"android:textSize="20sp"android:textColor="#000"android:layout_marginBottom="10dp"/><CheckBoxandroid:id="@+id/cb_1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Android"android:textSize="20sp"android:layout_below="@+id/tv_title"/><CheckBoxandroid:id="@+id/cb_2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="iOS"android:textSize="20sp"android:layout_below="@+id/cb_1"/><CheckBoxandroid:id="@+id/cb_3"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="H5"android:textSize="20sp"android:layout_below="@+id/cb_2"/><CheckBoxandroid:id="@+id/cb_4"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="其他"android:textSize="20sp"android:layout_below="@+id/cb_3"/><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="vertical"android:layout_below="@id/cb_4"android:layout_marginTop="20dp"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="你的兴趣"android:textSize="20sp"android:textColor="#000" /><CheckBoxandroid:id="@+id/cb_5"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="编程"android:button="@drawable/bg_checkbox"android:paddingLeft="10dp"android:textSize="20sp"android:layout_marginTop="10dp"/><CheckBoxandroid:id="@+id/cb_6"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="做饭"android:button="@drawable/bg_checkbox"android:paddingLeft="10dp"android:textSize="20sp"android:layout_marginTop="10dp"/></LinearLayout></RelativeLayout>

2-7 ImageView

  • Button的其他行生控件:ToggleButton、Switch
  • 常用属性
  • 加载网络图片

scaleType

  • fitXY:撑满控件,宽高比可能发生改变
  • fitCenter:保持宽高比缩放,直至能够完全显示
  • centerCrop:保持宽高比缩放,直至完全覆盖控件,裁剪显示

https://github.com/bumptech/glide

2-8 列表视图 ListView

  • 常用属性
  • Adapter
  • 演示Demo
package com.example.helloworld.listview;import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;import androidx.annotation.Nullable;import com.example.helloworld.R;public class ListViewActivity extends Activity {private ListView mLv1;@SuppressLint("MissingInflatedId")@Overrideprotected void onCreate(@Nullable Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.acticity_listview);mLv1 = (ListView) findViewById(R.id.lv_1);mLv1.setAdapter(new MyListAdapter(ListViewActivity.this));mLv1.setOnItemClickListener(new AdapterView.OnItemClickListener() {@Overridepublic void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {Toast.makeText(ListViewActivity.this,"点击pos:"+i,Toast.LENGTH_SHORT).show();//挑转}});mLv1.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {@Overridepublic boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {Toast.makeText(ListViewActivity.this,"长按pos:"+i,Toast.LENGTH_SHORT).show();return true;//结束处理}});}
}
package com.example.helloworld.listview;import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;import com.bumptech.glide.Glide;
import com.example.helloworld.R;public class MyListAdapter extends BaseAdapter {private Context mContext;private LayoutInflater mLayoutInflater;MyListAdapter(Context context) {this.mContext = context;mLayoutInflater = LayoutInflater.from(context);}@Overridepublic int getCount() {return 10;}@Overridepublic Object getItem(int i) {return null;}@Overridepublic long getItemId(int i) {return 0;}static class ViewHolder {public ImageView imageView;public TextView tvTitle, tvTime, tvContent;}@Overridepublic View getView(int i, View view, ViewGroup viewGroup) {ViewHolder holder = null;if (view == null) {view = mLayoutInflater.inflate(R.layout.layout_list_item, null);holder = new ViewHolder();holder.imageView = (ImageView) view.findViewById(R.id.iv);holder.tvTitle = (TextView) view.findViewById(R.id.tv_title);holder.tvTime = (TextView) view.findViewById(R.id.tv_time);holder.tvContent = (TextView) view.findViewById(R.id.tv_content);view.setTag(holder);}else {holder = (ViewHolder) view.getTag();}//给控件赋值holder.tvTitle.setText("这是标题");holder.tvTime.setText("2088-08-08");holder.tvContent.setText("这是内容");Glide.with(mContext).load("https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png").into(holder.imageView);return view;}
}

acticity_listview.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="match_parent"android:layout_height="match_parent"><ListViewandroid:id="@+id/lv_1"android:layout_width="match_parent"android:layout_height="wrap_content"android:listSelector="@drawable/list_item"/>
</LinearLayout>

layout_list_item.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:paddingLeft="15dp"android:paddingRight="15dp"android:paddingTop="10dp"android:paddingBottom="10dp"><ImageViewandroid:id="@+id/iv"android:layout_width="100dp"android:layout_height="100dp"android:scaleType="fitCenter"android:background="#000"/><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="vertical"android:paddingLeft="10dp"><TextViewandroid:id="@+id/tv_title"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Hello"android:textSize="20sp"android:textColor="@color/colorBlack"/><TextViewandroid:id="@+id/tv_time"android:layout_width="wrap_content"android:layout_height="wrap_content"android:textSize="18sp"android:layout_marginTop="10dp"android:text="2017-08-26"android:textColor="@color/colorGrayDark"/><TextViewandroid:id="@+id/tv_content"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginTop="10dp"android:textColor="@color/colorGrayDark"android:textSize="18sp"android:text="这是内容"/></LinearLayout>
</LinearLayout>

2-9 网格视图 GridView

  • 常用属性
  • Adapter
  • 演示Demo

GridViewActivity
MyGridViewAdapter

activity_gridview.xml
layout_grid_item.xml

2-10 滚动视图 ScrollView

  • 垂直滚动:ScrollView
  • 水平滚动:HorizontalScrollView

子元素只能有一个

activity_main.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"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="vertical"><Buttonandroid:id="@+id/btn_textview"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="TextView"/><Buttonandroid:id="@+id/btn_button"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="Button"/><Buttonandroid:id="@+id/btn_edittext"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="EditText"android:textAllCaps="false"/><Buttonandroid:id="@+id/btn_radiobutton"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="RadioButton"android:textAllCaps="false"/><Buttonandroid:id="@+id/btn_checkbox"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="CheckBox"android:textAllCaps="false" /><Buttonandroid:id="@+id/btn_imageview"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="ImageView"android:textAllCaps="false" /><Buttonandroid:id="@+id/btn_listview"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="ListView"android:textAllCaps="false" /><Buttonandroid:id="@+id/btn_gridview"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="GridView"android:textAllCaps="false" /><HorizontalScrollViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"><LinearLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:orientation="horizontal"><Buttonandroid:layout_width="200dp"android:layout_height="300dp"android:text="Test"android:textAllCaps="false"/><Buttonandroid:layout_width="200dp"android:layout_height="300dp"android:text="Test"android:textAllCaps="false"/><Buttonandroid:layout_width="200dp"android:layout_height="300dp"android:text="Test"android:textAllCaps="false"/><Buttonandroid:layout_width="200dp"android:layout_height="300dp"android:text="Test"android:textAllCaps="false"/></LinearLayout></HorizontalScrollView></LinearLayout></ScrollView>

2-11-1 RecyclerView (一)

RecyclerView能够灵活实现大数据集的展示,视图的复用管理比ListView更好,能够显示列表、网格、瀑布流等形式,且不同的ViewHolder能够实现item多元化的功能。

但是使用起来会稍微麻烦一点,并且没有类似ListView的onItemClickListener监听事件,需要开发者自己实现。

新版不用加

implementation 'com.android.support.design:25.3.1'

使用的是这个
androidx.recyclerview.widget.RecyclerView

LinearAdapter
LinearRecyclerViewActivity
RecyclerViewActivity
activity_linear_recycler_view.xml
activity_recycler.xml
layout_linear_item.xml

2-11-2 RecyclerView (二)

  • 水平滚动
  • 网格布局

HorAdapter
HorRecyclerActivity
activity_hor_recycler.xml
layout_hor_item.xml

GridAdapter
GridRecyclerActivity
activity_grid_recycler.xml
layout_grid_recyclerview_item.xml

2-11-3 RecyclerView (三)

  • 瀑布流

PuRecyclerActivity
StaggeredGridAdapter
layout_staggered_grid_recyclerview_item.xml
activity_pu_recycler.xml

2-11-4 RecyclerView (四)

  • 不同的ViewHolder
  • XRecyclerView:addHeadView、addFootView、下拉刷新、上拉加载

LinearAdapter
layout_linear_item.xml
layout_linear_item_2.xml

2-12 WebView

  • 加载网页加载URL(网络或者本地assets文件夹下的html文件)
  • 加载html代码
  • Native和JavaScript相互调用

加载网络URL

  • webview.loadUrl( “http://www.tiantiantech.cn” );

加载assets下的html文件

  • webview.loadUrl( “file:///android_asset/test.html”);

加载html代码

  • webview.loadData();
  • webview.loadDataWithBaseURL();

网页的前进后退

  • webview.canGoBack()
  • webview.goBack()
  • webview.canGoForward()
  • webview.goForward()
  • webview.canGoBackOrForward(int steps)
  • webview.goBackOrForward(int steps)

按下返回键,默认是退出当前Activity,如果希望是WebView内页面后退

在这里插入图片描述

最后

迎着日光月光星光,直面风霜雨霜雪霜。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://xiahunao.cn/news/3245434.html

如若内容造成侵权/违法违规/事实不符,请联系瞎胡闹网进行投诉反馈,一经查实,立即删除!

相关文章

深入理解Session和Cookie的作用与联系

深入理解Session和Cookie的作用与联系 1、什么是Cookie&#xff1f;1、什么是Session&#xff1f;1、Session和Cookie的联系4、实际应用场景 &#x1f496;The Begin&#x1f496;点点关注&#xff0c;收藏不迷路&#x1f496; Session和Cookie是两个至关重要的概念&#xff0c…

30.【C语言】详解printf

1.printf&#xff08;print formate&#xff09;输入函数 01.简单使用 调用前要引用头文件 #include <stdio.h> printf("abc"); 默认情况下打印完光标停留在同一行 \n可以换行 printf("abc\n"); ​ printf("ab\nc"); ​ printf(…

leetcode-383.赎金信

题源 383.赎金信 题目描述 给你两个字符串&#xff1a;ransomNote 和 magazine &#xff0c;判断 ransomNote 能不能由 magazine 里面的字符构成。如果可以&#xff0c;返回 true &#xff1b;否则返回 false 。magazine 中的每个字符只能在 ransomNote 中使用一次。示例 1&…

Beelzebub过程记录及工具集

文章目录 靶场搭建靶场测试过程安装dirsearch扫描目录wpscan扫描破解 靶场搭建 https://download.vulnhub.com/beelzebub/Beelzebub.zip 下载解压镜像&#xff0c;从vmware打开。 一键式开机即可。 打开后配置网络。 确保网络可达。 靶场测试过程 首先使用nmap扫描网段的存…

SpringBoot项目如何使用自定义Repository

在公司实习的时候&#xff0c;遇到这样一个问题&#xff0c;就是当往数据库添加记录的时候&#xff0c;需要先去查看数据库中的记录数是否超过了最大限制&#xff0c;如果没有超过则进行添加&#xff1b;否则就需要删除先前的记录从而保证数据库中的记录数。这样的话&#xff0…

【EXCELL技巧篇】使用Excel公式,获取当前 Excel的Sheet页的名字

【通知】&#xff1a; 正式跟大家说个难过的消息&#xff0c;本来在「中国朝代史」结束后&#xff0c;开启的下一个专栏「中国近代史」前面几期做的还好好的&#xff0c;可是今天起正式通知审核不过&#xff0c;因为一些原因。 其实我对于历史这一块我还是很感兴趣的&#xff0…

极地生产力自主采样系统的观测:融池比例统计 MEDEA 融池比例数据集

Observations from the Autonomous Polar Productivity Sampling System. 极地生产力自主采样系统的观测结果 简介 该项目是美国国家航空航天局 ICESCAPE 大型项目的一部分&#xff0c;旨在研究浮游植物丰度的长期季节性变化与整个生长季节在波弗特海和楚科奇海测量到的海冰…

从 Pandas 到 Polars 十八:数据科学 2025,对未来几年内数据科学领域发展的预测或展望

我在2021年底开始使用Polars和DuckDB。我立刻意识到这些库很快就会成为数据科学生态系统的核心。自那时起&#xff0c;这些库的受欢迎程度呈指数级增长。 在这篇文章中&#xff0c;我做出了一些关于未来几年数据科学领域的发展方向和原因的预测。 这篇文章旨在检验我的预测能力…

计算机技术与软件专业技术资格(软考)纸质证书邮寄方法

电子版证书已经有网友指出说明方法了&#xff0c;参考 软考电子证书下载 注意如果下载的PDF文件值无法打开的话&#xff0c;可以选择查看&#xff0c;然后 ctrlp 打印为PDF, 也是另外的一种下载方法&#xff1b; 下面说一下纸质版证书邮寄方法 1&#xff1a;登录网站 中国计…

【保姆级】Python项目部署到Linux生产环境(uwsgi+python+flask+nginx服务器)

1.安装python 我这里是3.9.5版本 安装依赖&#xff1a; yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make -y 根据自己的需要下载对应的python版本&#xff1a; cd /usr/local wget https://www.python.or…

CyberVadis认证是什么

CyberVadis认证是一项全球性的、权威的、基于云的网络安全性评估和认证项目。它是由Altimeter公司开发的&#xff0c;专门针对云计算服务提供商、数据中心、软件即服务(SaaS)供应商、安全咨询服务公司和内部IT部门而设计的。 CyberVadis认证旨在评估和验证组织在网络安全方面的…

数电基础 - 硬件描述语言

目录 一. 简介 二. Verilog简介和基本程序结构 三. 应用场景 四. Verilog的学习方法 五.调式方法 一. 简介 硬件描述语言&#xff08;Hardware Description Language&#xff0c;HDL&#xff09;是用于描述数字电路和系统的形式化语言。 常见的硬件描述语言包括 VHDL&…

邮箱表单系统源码

邮箱表单简介 我们的邮箱表单系统是一个简洁高效的工具&#xff0c;旨在为用户提供一种便捷的方式来提交他们的邮箱地址。该系统可以用于订阅新闻通讯、注册活动、获取用户反馈等多种场景。 功能特点&#xff1a; 用户友好的界面&#xff1a; 表单设计简洁直观&#xff0c;用…

成功适配!极验设备指纹HarmonyOS 鸿蒙版官方下载

近日&#xff0c;华为开发者大会&#xff08;HDC 2024&#xff09;在东莞召开。在大会开幕日的首场主题演讲中&#xff0c;华为宣布当前已有TOP5000应用成为鸿蒙原生应用&#xff0c;350&#xff0b;SDK已适配HarmonyOS NEXT版本。其中&#xff0c;极验作为其重要伙伴&#xff…

AI自动生成PPT哪个软件好?高效制作PPT优选这4个

7.15初伏的到来&#xff0c;也宣告三伏天的酷热正式拉开序幕~在这个传统的节气里&#xff0c;人们以各种方式避暑纳凉&#xff0c;享受夏日的悠闲时光。 而除了传统的避暑活动&#xff0c;我们还可以用一种新颖的方式记录和分享这份夏日的清凉——那就是通过PPT的方式将这一传…

02 Git环境搭建

第2章&#xff1a;Git环境搭建 一、Git下载和安装 ​ 官网&#xff1a;Git (git-scm.com) 一&#xff09;安装主程序 ​ 准备安装包&#xff0c;双击安装 ​ 开始安装 ​ 选择安装位置 ​ 选择需要安装的组件&#xff08;默认&#xff09; ​ 选择文件夹菜单 ​ 选择编辑器&…

自适应巡航控制中的Stop Go功能详解

自适应巡航控制中的跟车行驶功能详解 文章目录 1. 背景介绍2. 功能定义3. 功能原理4. 传感器架构5. 实际应用案例6. 总结与展望 1. 背景介绍 自适应巡航控制&#xff08;Adaptive Cruise Control, ACC&#xff09;系统中的Stop & Go功能是提升驾驶舒适性和安全性的重要子…

Visual Studio2022中使用.Net 8 在 Windows 下使用 Worker Service 创建守护进程

Visual Studio2022中使用.Net 8 在 Windows 下创建 Worker Service 1 什么是 .NET Core Worker Service1.1 确认Visual Studio中安装了 ASP.NET和Web开发2 创建 WorkerService项目2.1 新建一个WorkerService项目2.2 项目结构说明3 将应用转换成 Windows 服务3.1 安装Microsoft.…

Spring与设计模式实战之策略模式

Spring与设计模式实战之策略模式 引言 在现代软件开发中&#xff0c;设计模式是解决常见设计问题的有效工具。它们提供了经过验证的解决方案&#xff0c;帮助开发人员构建灵活、可扩展和可维护的系统。本文将探讨策略模式在Spring框架中的应用&#xff0c;并通过实际例子展示…

【HarmonyOS】关于鸿蒙消息推送的心得体会 (一)

【HarmonyOS】关于鸿蒙消息推送的心得体会&#xff08;一&#xff09; 前言 这几天调研了鸿蒙消息推送的实现方式&#xff0c;形成了开发设计方案&#xff0c;颇有体会&#xff0c;与各位分享。 虽然没做之前觉得很简单的小功能&#xff0c;貌似只需要和华为服务器通信&…