Skip to content

Commit 81f9d5a

Browse files
author
FengChenSunshine
committed
1.修复当被绑定的View parent是LinearLayout并且使用了weight属性时内容视图weight属性无效问题.
2.优化绑定流程,使其可以绑定任何视图为内容视图而不会导致View原属性改变.
1 parent b6dd996 commit 81f9d5a

File tree

10 files changed

+109
-10
lines changed

10 files changed

+109
-10
lines changed

README.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
**step two :**
5454

5555
dependencies {
56-
implementation 'com.github.FengChenSunshine:UiStatus:1.0.4'
56+
implementation 'com.github.FengChenSunshine:UiStatus:1.0.5'
5757
}
5858
### 2.全局配置
5959
UiStatus库不提供任何状态的视图,完全由开发者自己自定义提供。
@@ -157,6 +157,12 @@
157157

158158
## 8.版本说明
159159

160+
### 1.0.5
161+
162+
1.修复当被绑定的View parent是LinearLayout并且使用了weight属性时内容视图weight属性无效问题.
163+
164+
2.优化绑定流程,使其可以绑定任何视图为内容视图而不会导致View原属性改变.
165+
160166
### 1.0.4
161167

162168
新增:
@@ -192,7 +198,7 @@
192198
## 10.最后,喜欢的话可以点个赞哦!!!
193199

194200
## 11.我的开源库链接
195-
1.[![](https://img.shields.io/badge/UiStatus-1.0.4-brightgreen.svg)](https://github.com/FengChenSunshine/UiStatus)是我的另一个开源库:一个简单且强大的Ui状态视图控制库!喜欢的可以看看,欢迎start!!!
201+
1.[![](https://img.shields.io/badge/UiStatus-1.0.5-brightgreen.svg)](https://github.com/FengChenSunshine/UiStatus)是我的另一个开源库:一个简单且强大的Ui状态视图控制库!喜欢的可以看看,欢迎start!!!
196202

197203
2.[![](https://img.shields.io/badge/SupportWidget-1.0.0-brightgreen.svg)](https://github.com/FengChenSunshine/SupportWidget)是我的另一个开源库:一个追求简单够用且强大的UI组件库!喜欢的可以看看,欢迎start!!!
198204

app/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ dependencies {
2929
implementation project (':uistatus')
3030
// implementation 'com.fengchen:ui-status:1.0.0'
3131
// implementation 'com.github.DuanLu1112:UiStatusStatus:1.0.0'
32-
// implementation 'com.github.FengChenSunshine:UiStatus:1.0.3'
32+
// implementation 'com.github.FengChenSunshine:UiStatus:1.0.4'
3333

3434
}

app/src/main/java/com/fengchen/uistatus/demo/HomeActivity.java

+5
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ protected void onCreate(Bundle savedInstanceState) {
3939
findViewById(R.id.btn_example_elfin_cancel).setOnClickListener(this);
4040
findViewById(R.id.btn_example_widget_bottom_floor).setOnClickListener(this);
4141
findViewById(R.id.btn_example_widget_float).setOnClickListener(this);
42+
findViewById(R.id.btn_test_weight).setOnClickListener(this);
4243

4344
mUiStatusController = UiStatusController.get().bind(this);
4445
mUiStatusController.changeUiStatusIgnore(UiStatus.CONTENT);
@@ -91,6 +92,10 @@ public void onClick(View v) {
9192
mUiStatusController.showWidget(UiStatus.WIDGET_FLOAT);
9293
}
9394
break;
95+
case R.id.btn_test_weight:
96+
Intent intent = ShellActivity.navigation(this, 2);
97+
startActivity(intent);
98+
break;
9499
}
95100
}
96101
}

app/src/main/java/com/fengchen/uistatus/demo/ShellActivity.java

+20-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.fengchen.uistatus.demo;
22

3+
import android.content.Context;
4+
import android.content.Intent;
35
import android.os.Bundle;
46
import android.support.annotation.Nullable;
57
import android.support.v7.app.AppCompatActivity;
@@ -15,15 +17,30 @@
1517
*/
1618
public class ShellActivity extends AppCompatActivity {
1719

20+
public static Intent navigation(Context context, int type) {
21+
Intent intent = new Intent(context, ShellActivity.class);
22+
intent.putExtra("type", type);
23+
return intent;
24+
}
25+
1826
@Override
1927
protected void onCreate(@Nullable Bundle savedInstanceState) {
2028
super.onCreate(savedInstanceState);
2129
setContentView(R.layout.activity_shell);
2230
Toolbar toolbar = findViewById(R.id.toolbar);
2331
toolbar.setTitle("Fragment 示例");
2432

25-
getSupportFragmentManager().beginTransaction()
26-
.replace(R.id.fl_container, new ExampleFragment())
27-
.commit();
33+
Intent intent = getIntent();
34+
int type = intent.getIntExtra("type", 1);
35+
if (1 == type) {
36+
getSupportFragmentManager().beginTransaction()
37+
.replace(R.id.fl_container, new ExampleFragment())
38+
.commit();
39+
} else if (2 == type) {
40+
getSupportFragmentManager().beginTransaction()
41+
.replace(R.id.fl_container, new TestWeightFragment())
42+
.commit();
43+
}
2844
}
45+
2946
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.fengchen.uistatus.demo;
2+
3+
import android.os.Bundle;
4+
import android.support.annotation.NonNull;
5+
import android.support.annotation.Nullable;
6+
import android.support.v4.app.Fragment;
7+
import android.view.LayoutInflater;
8+
import android.view.View;
9+
import android.view.ViewGroup;
10+
import android.widget.TextView;
11+
12+
import com.fengchen.uistatus.UiStatusController;
13+
import com.fengchen.uistatus.annotation.UiStatus;
14+
15+
/********************************
16+
* @name TestWeightFragment.
17+
* @author 段露.
18+
* @company 浙江托普云农科技股份有限公司.
19+
* @createDate 2020/3/30 9:45.
20+
* @updateDate 2020/3/30 9:45.
21+
* @version V1.0.0
22+
* @describe .
23+
********************************/
24+
public class TestWeightFragment extends Fragment {
25+
private UiStatusController mUiStatusController;
26+
27+
@Nullable
28+
@Override
29+
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
30+
View rootView = inflater.inflate(R.layout.fragment_test_weight, container, false);
31+
TextView tvTestWeight = rootView.findViewById(R.id.tv_test_weight);
32+
ViewGroup.LayoutParams lp = tvTestWeight.getLayoutParams();
33+
mUiStatusController = UiStatusController.get();
34+
mUiStatusController.bind(tvTestWeight);
35+
mUiStatusController.changeUiStatusIgnore(UiStatus.CONTENT);
36+
return rootView;
37+
}
38+
39+
}

app/src/main/res/layout/activity_home.xml

+9
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,15 @@
8888
android:layout_marginTop="10dp"
8989
android:layout_marginEnd="50dp"
9090
android:text="Float" />
91+
92+
<Button
93+
android:id="@+id/btn_test_weight"
94+
android:layout_width="match_parent"
95+
android:layout_height="wrap_content"
96+
android:layout_marginStart="50dp"
97+
android:layout_marginTop="10dp"
98+
android:layout_marginEnd="50dp"
99+
android:text="Test Weight" />
91100
</LinearLayout>
92101

93102
</LinearLayout>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent"
5+
android:background="#f40"
6+
android:orientation="vertical">
7+
8+
<TextView
9+
android:id="@+id/tv_test_weight"
10+
android:layout_width="wrap_content"
11+
android:layout_height="0dp"
12+
android:layout_gravity="center"
13+
android:layout_weight="1"
14+
android:background="#00ffcc"
15+
android:gravity="center"
16+
android:text="我是设置的weight"
17+
android:textSize="24sp" />
18+
19+
</LinearLayout>

uistatus/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ android {
77
defaultConfig {
88
minSdkVersion 14
99
targetSdkVersion 29
10-
versionCode 5
11-
versionName "1.0.4"
10+
versionCode 6
11+
versionName "1.0.5"
1212
}
1313

1414
buildTypes {

uistatus/config-aar.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ apply plugin: 'maven'
55
ext {
66
PUBLISH_GROUP_ID = project.properties.get("publishGroupId")
77
PUBLISH_ARTIFACT_ID = "ui-status"
8-
PUBLISH_VERSION = "1.0.0"
8+
PUBLISH_VERSION = "1.0.5"
99
PUBLISH_PATH = project.properties.get("publishRootPath") + "/UiStatus"
1010
}
1111
//3.配置maven输出路径及信息

uistatus/src/main/java/com/fengchen/uistatus/utils/BindHelp.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,14 @@ public static UiStatusLayout bindFragmentView(@NonNull View fragmentView) {
5656

5757
private static UiStatusLayout _bind(Object target, ViewGroup parentView, int index) {
5858
View contentView = parentView.getChildAt(index);
59+
//临时保存下lp,否则在创建UiStatusLayout时添加了contentView导致后面再通过getLayoutParams方法获取到的lp已经被改变.
60+
ViewGroup.LayoutParams lp = contentView.getLayoutParams();
61+
5962
parentView.removeViewAt(index);
63+
6064
UiStatusLayout uiStatusLayout = createUiStatusLayout(target, contentView);
6165

62-
parentView.addView(uiStatusLayout, index, contentView.getLayoutParams());
66+
parentView.addView(uiStatusLayout, index, lp);
6367

6468
//fix github issues bug #7.
6569
//因为UiStatusLayout设置的lp是ContentView的,

0 commit comments

Comments
 (0)