国际化支持、activity生命周期、屏幕翻转的ui适配
国际化
对于手机的不同语言做出不同的语言描述,这里只是简单的提一下,实际上针对比较大型的项目,有可能不同的语言要做不同的ui适配。
例如下面:中文长度不长但是在德语中占据很长的位置,这个就要针对性的适配

这里只讲想法:
1、打开strings.xml点击
2、点击
3、选择简体中文

4、前后结果对比
未添加中文之前:

添加之后:

编辑(英文情况下app名为Localization,中文情况app名为本地化)

activity生命周期
android由一个个activity构成,所以在影视app可以直接跳转到微信的分享界面,一个activity的生命周期如下图:
onCreate():当我们点击activity的时候,系统会调用activity的oncreate()方法,在这个方法中我们会初始化当前布局setContentLayout()方法。
onStart():onCreate()方法完成后,此时activity进入onStart()方法,当前activity是用户可见状态,但没有焦点,与用户不能交互,一般可在当前方法做一些动画的初始化操作。
onResume():onStart()方法完成之后,此时activity进入onResume()方法中,当前activity状态属于运行状态 (Running),可与用户进行交互。
onPause():当另外一个activity覆盖当前的acitivty时,此时当前activity会进入到onPause()方法中,当前activity是可见的,但不能与用户交互状态。
onStop():onPause()方法完成之后,此时activity进入onStop()方法,此时activity对用户是不可见的,在系统内存紧张的情况下,有可能会被系统进行回收。所以一般在当前方法可做资源回收。
onDestory():onStop()方法完成之后,此时activity进入到onDestory()方法中,结束当前activity。
onRestart():onRestart()方法在用户按下home()之后,再次进入到当前activity的时候调用。调用顺序onPause()->onStop()->onRestart()->onStart()->onResume().

1、running->当前显示在屏幕的activity(位于任务栈的顶部),用户可见状态。
2、poused->依旧在用户可见状态,但是界面焦点已经失去,此Activity无法与用户进行交互。
3、stopped->用户看不到当前界面,也无法与用户进行交互 完全被覆盖.
4、killed->当前界面被销毁,等待这系统被回收

屏幕翻转ui适配
屏幕翻转activity会被销毁所以之前要保存屏幕的信息。
用到的api:public void onSaveInstanceState(Bundle outState)
public void onSaveInstanceState(Bundle outState) {
//由于屏幕翻转activity会destory所以需要保存之前的屏幕信息
super.onSaveInstanceState(outState);//该默认的方法是实现 组件状态保存的,比如开关的状态
outState.putString("showText",textView.getText().toString());
}
保持屏幕ui不随屏幕翻转而改变:在AndroidMainfest中修改这一句:
<!-- 设置应用的ui不随屏幕翻转而改变-->
<activity android:name=".MainActivity"
android:screenOrientation="portrait" >
不同情况ui不同举例:
竖屏电话:

横屏电话:

Demo
竖屏ui:

点击切换到水平
水平ui:

activity_main.xml
```xml
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:text="@string/textview"
android:textSize="30sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/guideline" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.0" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.33" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.66" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.66" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.99" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.33" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button1"
app:layout_constraintBottom_toTopOf="@+id/guideline3"
app:layout_constraintEnd_toStartOf="@+id/guideline6"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/guideline2" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button2"
app:layout_constraintBottom_toTopOf="@+id/guideline3"
app:layout_constraintEnd_toStartOf="@+id/guideline7"
app:layout_constraintStart_toStartOf="@+id/guideline6"
app:layout_constraintTop_toTopOf="@+id/guideline2" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button3"
app:layout_constraintBottom_toTopOf="@+id/guideline3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/guideline7"
app:layout_constraintTop_toTopOf="@+id/guideline2" />
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button4"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/guideline6"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/guideline3" />
<Button
android:id="@+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button5"
app:layout_constraintBottom_toTopOf="@+id/guideline5"
app:layout_constraintEnd_toStartOf="@+id/guideline7"
app:layout_constraintStart_toStartOf="@+id/guideline6"
app:layout_constraintTop_toTopOf="@+id/guideline3" />
<Button
android:id="@+id/button6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button6"
app:layout_constraintBottom_toTopOf="@+id/guideline5"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/guideline7"
app:layout_constraintTop_toTopOf="@+id/guideline3"
app:layout_constraintVertical_bias="0.482" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.66" />
</androidx.constraintlayout.widget.ConstraintLayout>
参考链接:https://blog.csdn.net/xiajun2356033/article/details/78741121
国际化支持、activity生命周期、屏幕翻转的ui适配的更多相关文章
- 基础总结篇之一:Activity生命周期
子曰:溫故而知新,可以為師矣.<論語> 学习技术也一样,对于技术文档或者经典的技术书籍来说,指望看一遍就完全掌握,那基本不大可能,所以我们需要经常回过头再仔细研读几遍,以领悟到作者的思想精 ...
- Android编程: Activity生命周期和LogCat使用
学习内容:Activity生命周期和LogCat使用 ====Activity生命周期==== 图示(转载): 创建 onCreate重启 onRestart开始 onStart恢复 ...
- [JIT_APP]Activity生命周期相关的7个方法
先发一张安卓官方文档里面的Activity生命周期图解 下面在对这7个生命周期内相关的方法做一些简单的介绍 OnCreate() 当Activity被创建的时候,会自动运行该方法.该方法做一些初始化动 ...
- 基础总结篇之中的一个:Activity生命周期
子曰:溫故而知新,能够為師矣.<論語> 学习技术也一样,对于技术文档或者经典的技术书籍来说,指望看一遍就全然掌握,那基本不大可能,所以我们须要常常回过头再细致研读几遍,以领悟到作者的思想精 ...
- 转:基础总结篇之一:Activity生命周期
熟悉javaEE的朋友们都了解servlet技术,我们想要实现一个自己的servlet,需要继承相应的基类,重写它的方法,这些方法会在合适的时间被servlet容器调用.其实android中的Acti ...
- 文章之间的基本总结:Activity生命周期
孔子:温故而知新.它可以作为一个教师.<论语> 同样的学习技巧.对于技术文件或书籍的经典技术,期待再次看到它完全掌握,这基本上是不可能的,所以,我们常常回来几次,然后仔细研究,为了理解作者 ...
- 了解Activity生命周期
当用户浏览,退出和返回您的应用时,您应用中的activity实例会在其生命周期中的不同状态中进行转换. Activity类提供了许多回调,允许activity知道状态已更改:系统正在创建,停止或恢复a ...
- 基础总结篇之一:Activity生命周期[转]
from:http://blog.csdn.net/liuhe688/article/details/6733407 基础总结篇之一:Activity生命周期 子曰:溫故而知新,可以為師矣.< ...
- onWindowFocusChanged重要作用 and Activity生命周期
onWindowFocusChanged重要作用 Activity生命周期中,onStart, onResume, onCreate都不是真正visible的时间点,真正的visible时间点是onW ...
随机推荐
- CSS伪类before,after制作左右横线中间文字效果
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 为mongoDB加用户权限管理
MongoDB常用命令 > show dbs #显示数据库列表 > show collections #显示当前数据库中的集合(类似关系数据 ...
- 对malloc和free和数据结构和算法的一些感触
当年2013.9.大一学c程序设计,因为当时还没有学数据结构,只学了程序设计,大学上的课真的是承上启下的不好,刚学到这里,就断了旋一样,对这个malloc和free一直很迷惑,这些狗玩意是干嘛,因为用 ...
- jmeter下载安装---已有jmeter脚本使用方法
一.jmeter下载安装 1.下载地址:http://jmeter.apache.org/download_jmeter.cgi 下载下来为一个压缩包,解压即可 解压后目录结构如下: 2.jmeter ...
- Python之旅第二天(第一天补充部分、数据类型、运算逻辑、部分方法的引入、pycharm)
今天其实是有点小忙的,但是干自己不喜欢事情的结果就是,要睡觉了都不知道自己在忙鸡毛,所以还是不继续想了,脑仁疼.回忆一下今天的学习内容,着实有点少,本大侠还没怎么过瘾呢.废话不多说. while补充两 ...
- echart如何去掉X 、Y轴的网格线
1.如何去掉X.Y轴的网格线,关键是splitLine{show:false} xAxis:[{ type:'value', splitNumber:2, scale:true, splitLine: ...
- 第三十三篇 玩转数据结构——红黑树(Read Black Tree)
1.. 图解2-3树维持绝对平衡的原理: 2.. 红黑树与2-3树是等价的 3.. 红黑树的特点 简要概括如下: 所有节点非黑即红:根节点为黑:NULL节点为黑:红节点孩子为黑:黑平衡 4.. 实现红 ...
- TCP/IP协议-为什么说TCP是可靠连接
我们平常经常说UDP是不可靠连接,TCP是可靠连接,然而TCP为什么是可靠的呢 1. TCP和UDP的优缺点TCP 缺点: [1] 三次握手四次挥手,传输更多包,浪费一些带宽[2] 为了进行可靠通信, ...
- Apache Kafka(十)Partitions与Replication Factor 调整准则
Partitions与Replication Factor调整准则 Partition 数目与Replication Factor是在创建一个topic时非常重要的两个参数,这两个参数的取值会直接影响 ...
- 安装Nginx:通过yum方式
1.配置yum源: 在/etc/yum.repos.d中新建后缀为.repo的文件,此处以nginx.repo为例. 2.更新yum源: yum clean all yum makecache 3 ...