Skip to content

Commit 0effa4f

Browse files
committed
解决wrap_content无高度问题
1 parent a59adb2 commit 0effa4f

File tree

19 files changed

+35
-232
lines changed

19 files changed

+35
-232
lines changed

.idea/modules.xml

+4-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

+13-5
Original file line numberDiff line numberDiff line change
@@ -33,43 +33,51 @@
3333
app:wkp_stick="true"
3434
android:orientation="horizontal"
3535
android:layout_width="match_parent"
36-
android:layout_height="40dp">
36+
android:layout_height="wrap_content">
3737

3838
<TextView
3939
android:onClick="scrollTo2"
40+
android:paddingTop="10dp"
41+
android:paddingBottom="10dp"
4042
android:background="@android:color/holo_blue_light"
4143
android:text="NUM2"
4244
android:gravity="center"
4345
android:layout_weight="1"
4446
android:layout_width="0dp"
45-
android:layout_height="match_parent"/>
47+
android:layout_height="wrap_content"/>
4648

4749
<TextView
4850
android:onClick="scrollTo3"
51+
android:paddingTop="10dp"
52+
android:paddingBottom="10dp"
4953
android:background="@android:color/holo_green_light"
5054
android:text="NUM3"
5155
android:gravity="center"
5256
android:layout_weight="1"
5357
android:layout_width="0dp"
54-
android:layout_height="match_parent"/>
58+
android:layout_height="wrap_content"/>
5559

5660
<TextView
5761
android:onClick="scrollTo4"
62+
android:paddingTop="10dp"
63+
android:paddingBottom="10dp"
5864
android:background="@android:color/holo_red_light"
5965
android:text="NUM4"
6066
android:gravity="center"
6167
android:layout_weight="1"
6268
android:layout_width="0dp"
63-
android:layout_height="match_parent"/>
69+
android:layout_height="wrap_content"/>
6470

6571
<TextView
6672
android:onClick="scrollTo7"
73+
android:paddingTop="10dp"
74+
android:paddingBottom="10dp"
6775
android:background="@android:color/holo_orange_light"
6876
android:text="NUM7"
6977
android:gravity="center"
7078
android:layout_weight="1"
7179
android:layout_width="0dp"
72-
android:layout_height="match_parent"/>
80+
android:layout_height="wrap_content"/>
7381

7482
</LinearLayout>
7583

sticklayout-lib/build.gradle

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ android {
1111
// applicationId "com.wkp.sticklayout_lib"
1212
minSdkVersion 15
1313
targetSdkVersion 26
14-
versionCode 5
15-
versionName "1.0.5"
14+
versionCode 6
15+
versionName "1.0.6"
1616

1717
}
1818

@@ -34,7 +34,7 @@ publish {
3434
userOrg = 'wkp'
3535
groupId = 'com.wkp'
3636
artifactId = 'StickLayout'
37-
publishVersion = '1.0.5'
37+
publishVersion = '1.0.6'
3838
desc = 'a library to create a stickable layout'
3939
website = 'https://github.com/wkp111/StickLayout'
4040
}

sticklayout-lib/src/main/AndroidManifest.xml

+8-8
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="com.wkp.sticklayout_lib">
44

5-
<application
6-
android:allowBackup="true"
7-
android:icon="@mipmap/ic_launcher"
8-
android:label="@string/app_name"
9-
android:roundIcon="@mipmap/ic_launcher_round"
10-
android:supportsRtl="true"
11-
android:theme="@style/AppTheme">
12-
</application>
5+
<!--<application-->
6+
<!--android:allowBackup="true"-->
7+
<!--android:icon="@mipmap/ic_launcher"-->
8+
<!--android:label="@string/app_name"-->
9+
<!--android:roundIcon="@mipmap/ic_launcher_round"-->
10+
<!--android:supportsRtl="true"-->
11+
<!--android:theme="@style/AppTheme">-->
12+
<!--</application>-->
1313

1414
</manifest>

sticklayout-lib/src/main/java/com/wkp/sticklayout_lib/widget/StickLayout.java

+7
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,13 @@ protected void onScrollChanged(int l, int t, int oldl, int oldt) {
720720
@Override
721721
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
722722
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
723+
//确定替代控件的大小
724+
View replaceView = mViewPair.first;
725+
View originalView = mViewPair.second;
726+
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) replaceView.getLayoutParams();
727+
params.width = originalView.getMeasuredWidth();
728+
params.height = originalView.getMeasuredHeight();
729+
replaceView.setLayoutParams(params);
723730

724731
if (!mFillViewport) {
725732
return;

sticklayout-lib/src/main/res/drawable-v24/ic_launcher_foreground.xml

-34
This file was deleted.

sticklayout-lib/src/main/res/drawable/ic_launcher_background.xml

-171
This file was deleted.

sticklayout-lib/src/main/res/mipmap-anydpi-v26/ic_launcher.xml

-5
This file was deleted.

sticklayout-lib/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml

-5
This file was deleted.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)