Skip to content

Commit

Permalink
20191111
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaofengyi committed Nov 11, 2019
1 parent ecb97ca commit c60e2f8
Show file tree
Hide file tree
Showing 15 changed files with 1,002 additions and 20 deletions.
10 changes: 5 additions & 5 deletions Algorithms/basic_knowledge.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@



![image](/Users/zhaofengyi/Documents/gitbook/Algorithms/pic/discrete_sum.png)
![image](./pic/discrete_sum.png)



![image](/Users/zhaofengyi/Documents/gitbook/Algorithms/pic/common_cost.png)
![image](./pic/common_cost.png)

![image](/Users/zhaofengyi/Documents/gitbook/Algorithms/pic/capability.png)
![image](./pic/capability.png)

Theta, O, Omega, Tilde记号:

![image](/Users/zhaofengyi/Documents/gitbook/Algorithms/pic/notation1.png)
![image](./pic/notation1.png)

| 记号 | 含义 |
| ---------- | ---------------------- |
Expand All @@ -30,7 +30,7 @@ Theta, O, Omega, Tilde记号:

误区:把O(N)当做近似模型,应该用 ~ N

![image](/Users/zhaofengyi/Documents/gitbook/Algorithms/pic/notation2.png)
![image](./pic/notation2.png)



Expand Down
91 changes: 80 additions & 11 deletions Android/WorkExperience/android.adatper.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,20 @@

## 屏幕适配

1. 用AndroidStudio插件ScreenMatch根据屏幕尺寸生成不同的dimen
#### 定义多种分辨率的dimens.xml(不推荐)

用AndroidStudio插件ScreenMatch根据屏幕尺寸生成不同的dimen

https://www.jianshu.com/p/1302ad5a4b04

https://github.com/wildma/ScreenAdaptation/blob/master/app/src/main/res/values/dimens.xml

不能应对density变化?

2. 用限制性布局ConstraintLayout

少用dp值,多用百分比

可以应对density变化
#### 用限制性布局ConstraintLayout

> implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
> implementation 'com.android.support.constraint:constraint-layout:1.1.3'

```xml
<?xml version="1.0" encoding="utf-8"?>
Expand Down Expand Up @@ -67,12 +65,83 @@ https://github.com/wildma/ScreenAdaptation/blob/master/app/src/main/res/values/d
</android.support.constraint.ConstraintLayout>
```

* 图片用.9或者svg; 多用相对布局,尽量不用绝对布局;


#### 用自适应TextView
https://blog.csdn.net/Virgil_K2017/article/details/88725298

> implementation 'androidx.appcompat:appcompat:1.1.0'

8.0以上:

```xml
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintWidth_default="percent"
app:layout_constraintWidth_percent="0.3"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintHorizontal_bias="0.1"
app:layout_constraintVertical_bias="0.7"
android:text="012345678901234567890"
android:gravity="center"
android:maxLines="1"
android:ellipsize="end"
android:textSize="25dp"
android:autoSizeTextType="uniform"
android:autoSizeMaxTextSize="25dp"
android:autoSizeMinTextSize="20dp"
android:autoSizeStepGranularity="1dp" />
```

8.0以下:

```
implementation 'com.android.support:appcompat-v7:28.0.0'
```

```xml
<android.support.v7.widget.AppCompatTextView
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintWidth_default="percent"
app:layout_constraintWidth_percent="0.3"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintHorizontal_bias="0.7"
app:layout_constraintVertical_bias="0.7"
android:text="012345678901234567890"
android:gravity="center"
android:maxLines="1"
android:ellipsize="end"
android:textSize="25dp"
app:autoSizeTextType="uniform"
app:autoSizeMaxTextSize="25dp"
app:autoSizeMinTextSize="20dp"
app:autoSizeStepGranularity="1dp"/>
```

androidx的话用`androidx.appcompat.widget.AppCompatTextView`



#### 其他

* 图片用.9或者svg
* 多用相对布局,尽量不用绝对布局
* 少用dp值,多用百分比



## 安卓版本适配

通过gradle flavor选择不同的source set



3. 通过gradle flavor选择不同的sourceset
4. 用自适应textview
https://blog.csdn.net/Virgil_K2017/article/details/88725298
79 changes: 75 additions & 4 deletions Android/WorkExperience/force.landscape.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,22 @@ index 750bad6..6b34af6 100644
### recovery UI
用命令`convert progress_fill.png -rotate 90 progress_fill.png && convert progress_empty.png -rotate 90 progress_empty.png` 把以下图片旋转90度:
res-hdpi/images/progress_empty.png
res-hdpi/images/progress_fill.png
res-mdpi/images/progress_empty.png
res-mdpi/images/progress_fill.png
res-xhdpi/images/progress_empty.png
res-xhdpi/images/progress_fill.png
res-xxhdpi/images/progress_empty.png
res-xxhdpi/images/progress_fill.png
res-xxxhdpi/images/progress_empty.png
res-xxxhdpi/images/progress_fill.png
```cpp
diff --git a/screen_ui.cpp b/screen_ui.cpp
index b8f6ea2..69db797 100644
index b8f6ea2..153d1b1 100644
--- a/screen_ui.cpp
+++ b/screen_ui.cpp
@@ -170,8 +170,8 @@ void ScreenRecoveryUI::draw_background_locked() {
Expand All @@ -199,15 +212,73 @@ index b8f6ea2..69db797 100644
gr_blit(frame, 0, 0, frame_width, frame_height, frame_x, frame_y);
}
@@ -460,6 +460,7 @@ void ScreenRecoveryUI::LoadBitmap(const char* filename, GRSurface** surface) {
@@ -193,8 +193,8 @@ void ScreenRecoveryUI::draw_foreground_locked() {
int width = gr_get_width(progressBarEmpty);
int height = gr_get_height(progressBarEmpty);
- int progress_x = (gr_fb_width() - width) / 2;
- int progress_y = GetProgressBaseline();
+ int progress_x = (gr_fb_width() - width) / 5; //(gr_fb_width() - width) / 2;
+ int progress_y = (gr_fb_height() - height) / 2; //GetProgressBaseline();
// Erase behind the progress bar (in case this was a progress-only update)
gr_color(0, 0, 0, 255);
@@ -202,24 +202,27 @@ void ScreenRecoveryUI::draw_foreground_locked() {
if (progressBarType == DETERMINATE) {
float p = progressScopeStart + progress * progressScopeSize;
- int pos = static_cast<int>(p * width);
+ int pos = static_cast<int>(p * height);
if (rtl_locale_) {
// Fill the progress bar from right to left.
if (pos > 0) {
- gr_blit(progressBarFill, width - pos, 0, pos, height, progress_x + width - pos,
- progress_y);
+ //gr_blit(progressBarFill, width - pos, 0, pos, height, progress_x + width - pos, progress_y);
+ gr_blit(progressBarFill, 0, height - pos, width, pos, progress_x, progress_y + width - pos);
}
- if (pos < width - 1) {
- gr_blit(progressBarEmpty, 0, 0, width - pos, height, progress_x, progress_y);
+ if (pos < height - 1) {
+ //gr_blit(progressBarEmpty, 0, 0, width - pos, height, progress_x, progress_y);
+ gr_blit(progressBarEmpty, 0, 0, width, height - pos, progress_x, progress_y);
}
} else {
// Fill the progress bar from left to right.
if (pos > 0) {
- gr_blit(progressBarFill, 0, 0, pos, height, progress_x, progress_y);
+ //gr_blit(progressBarFill, 0, 0, pos, height, progress_x, progress_y);
+ gr_blit(progressBarFill, 0, 0, width, pos, progress_x, progress_y);
}
- if (pos < width - 1) {
- gr_blit(progressBarEmpty, pos, 0, width - pos, height, progress_x + pos, progress_y);
+ if (pos < height - 1) {
+ //gr_blit(progressBarEmpty, pos, 0, width - pos, height, progress_x + pos, progress_y);
+ gr_blit(progressBarEmpty, 0, pos, width, height - pos, progress_x, progress_y + pos);
}
}
}
@@ -460,6 +463,7 @@ void ScreenRecoveryUI::LoadBitmap(const char* filename, GRSurface** surface) {
void ScreenRecoveryUI::LoadLocalizedBitmap(const char* filename, GRSurface** surface) {
int result = res_create_localized_alpha_surface(filename, locale_.c_str(), surface);
+ RotateSurface(*surface);
if (result < 0) {
LOG(ERROR) << "couldn't load bitmap " << filename << " (error " << result << ")";
}
@@ -841,3 +842,29 @@ void ScreenRecoveryUI::KeyLongPress(int) {
@@ -611,8 +615,8 @@ void ScreenRecoveryUI::SetProgress(float fraction) {
if (fraction > 1.0) fraction = 1.0;
if (progressBarType == DETERMINATE && fraction > progress) {
// Skip updates that aren't visibly different.
- int width = gr_get_width(progressBarEmpty);
- float scale = width * progressScopeSize;
+ int height = gr_get_height(progressBarEmpty);
+ float scale = height * progressScopeSize;
if ((int)(progress * scale) != (int)(fraction * scale)) {
progress = fraction;
update_progress_locked();
@@ -841,3 +845,29 @@ void ScreenRecoveryUI::KeyLongPress(int) {
// will change color to indicate a successful long press.
Redraw();
}
Expand Down Expand Up @@ -236,7 +307,7 @@ index b8f6ea2..69db797 100644
+ delete []src;
+ return;
+}
+
+
```
```cpp
Expand Down
122 changes: 122 additions & 0 deletions Android/WorkExperience/gridlayout.height.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# GridLayout

参考: https://www.jianshu.com/p/441d60be7d8a

GridLayout的每一项宽高只能是:

wrap_content;

一个写死的xxdp值;

根据设置的column平分;

但是项目需要适配好一点的话,最好可以动态设置宽高。

```java
setLayoutManager(new GridLayoutManager(this, columeNum));
```

这样宽可以自动均分了;

高度是测量第1行中所有子View的高,取最大值作为该行的高,如果该行没有子View,行高设为0。

> GridLayout的子View不需要设置layout_width和layout_height属性,因为GridLayout会把所有的子View的这两个属性设置为WRAP_CONTENT,所以你设置了也没有用。
1. 高度跟宽一样

在子view的onMeasure里面把宽高设成一样

```xml
<com.moos.launcher.CustomConstraintlayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent">
...
</com.moos.launcher.CustomConstraintlayout>
```



```java
package com.moos.launcher;

import android.content.Context;
import android.util.AttributeSet;

import androidx.constraintlayout.widget.ConstraintLayout;

public class CustomConstraintlayout extends ConstraintLayout {
public CustomConstraintlayout(Context context) {
super(context);
}

public CustomConstraintlayout(Context context, AttributeSet attrs) {
super(context, attrs);
}

public CustomConstraintlayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}


/**
* set height the same size with height;
* gridlayout计算子view最大高度,设置为这一行的高度;
* 但是这里希望直接设置为跟宽度一样,而不用依赖子view的高度;
* 这样子view可以用constraintlayout,根据父view的高度来布局
* 所有的布局都不需要写dp值,只写比例值即可
* @param widthMeasureSpec
* @param heightMeasureSpec
*/
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, widthMeasureSpec);
setMeasuredDimension(getMeasuredWidth(), getMeasuredWidth());
}
}
```



2. 高度根据父view的高度均分

Adatper中设置子view的子view的高度

>为什么不设置子view, 因为上面说了,子view不管设置成什么,结果都是wrap_content
```xml
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/max_height_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent">
... </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
```



```java
@NonNull
@Override
public XXXViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.XXX_item, null);
View maxHeightView = view.findViewById(R.id.max_height_view);
ConstraintLayout.LayoutParams layoutParams = (ConstraintLayout.LayoutParams) maxHeightView.getLayoutParams();
layoutParams.height = mRecyclerView.getHeight() / 3;
// 这里设置成父view的1/3
maxHeightView.setLayoutParams(layoutParams);
return new XXXViewHolder(view);
}
```

Loading

0 comments on commit c60e2f8

Please sign in to comment.