No resource found that matches given name… '@dimen/abc_action_bar_default_height'

本文介绍了解决Android项目在SDK升级后遇到的资源找不到错误的方法。具体表现为使用特定尺寸作为padding属性值时报错。解决办法是用属性引用替代直接引用资源文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

该问题往往是老项目sdk的编译版本升级时出现的,例如:
升级前:

compileSdkVersion 20
buildToolsVersion '21.1.2'

升级后:

compileSdkVersion 23
buildToolsVersion '23.0.2'
compile 'com.android.support:support-v13:23.1.0'

报错:

No resource found that matches the given name (at 'paddingTop' with value '@dimen/abc_action_bar_default_height').

问题出在:

android:paddingTop="@dimen/abc_action_bar_default_height"

解决方法:

使用?attr/actionBarSize代替actionBar大小,例如android:paddingTop="?attr/actionBarSize"
这是因为升级之后的支持库中对外隐藏了xml 资源的使用。

<com.hryt.design.base.HHConstraintLayout android:layout_width="wrap_content" android:layout_height="@dimen/dimen_416" android:visibility="@{isGuide ? View.GONE : View.VISIBLE}" android:background="@drawable/map_scroll"> <com.hryt.design.toggle.HHToggleButton android:id="@+id/route_plan_service" android:layout_width="@dimen/dimen_264" android:layout_height="@dimen/dimen_154" android:clickable="true" android:gravity="center" android:splitMotionEvents="false" android:text="@string/guide_route_along_way_service" android:textStyle="bold" android:textSize="@dimen/font_28" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:hryt_toggleType="rectangle"/> <com.hryt.design.toggle.HHToggleButton android:id="@+id/route_plan_cloudy" android:layout_width="@dimen/dimen_264" android:layout_height="@dimen/dimen_154" android:clickable="true" android:gravity="center" android:splitMotionEvents="false" app:layout_constraintTop_toTopOf="parent" android:layout_marginTop="@dimen/dimen_122" android:text="@string/guide_route_along_way_cloudy" android:textStyle="bold" android:textSize="@dimen/font_28" app:layout_constraintStart_toStartOf="parent" app:hryt_toggleType="rectangle"/> <com.hryt.design.toggle.HHToggleButton android:id="@+id/route_road" android:layout_width="@dimen/dimen_264" android:layout_height="@dimen/dimen_154" android:clickable="true" android:gravity="center" android:splitMotionEvents="false" app:layout_constraintBottom_toBottomOf="parent" android:text="@string/guide_route_along_way_road" android:textStyle="bold" android:textSize="@dimen/font_28" app:layout_constraintStart_toStartOf="parent" app:hryt_toggleType="rectangle"/> </com.hryt.design.base.HHConstraintLayout>
06-02
<think>根据提供的布局代码,`SmartRefreshHorizontal` 被包裹在一个 `RelativeLayout` 中,并且 `RelativeLayout` 设置了 `android:paddingBottom="@dimen/dp_16"`,同时内部还有一个 `AppCompatSeekBar` 固定在底部。这可能导致 `SmartRefreshHorizontal` 无法占满全屏,因为底部有内边距,并且底部有一个 `SeekBar` 覆盖在 `SmartRefreshHorizontal` 的底部。 ### 问题分析: 1. **`RelativeLayout` 的 `paddingBottom`**:设置了底部内边距,导致子视图无法延伸到布局底部。 2. **`SeekBar` 的位置**:`SeekBar` 使用 `layout_alignParentBottom` 固定在底部,并设置了 `layout_marginBottom`,这可能会覆盖在 `SmartRefreshHorizontal` 的底部,从而影响内容区域。 ### 解决方案: #### 1. 移除 `RelativeLayout` 的底部内边距 将 `android:paddingBottom="@dimen/dp_16"` 移除,或者设置为0。 #### 2. 调整 `SeekBar` 的位置 如果需要在底部显示 `SeekBar`,可以调整 `SmartRefreshHorizontal` 的高度,避免被 `SeekBar` 覆盖。或者使用布局技巧,将 `SeekBar` 放在 `SmartRefreshHorizontal` 外部,但这样需要调整整个布局结构。 #### 3. 使用 `FrameLayout` 或调整视图层级 将 `SeekBar` 作为 `SmartRefreshHorizontal` 的兄弟视图,并调整 `SmartRefreshHorizontal` 的底部位置,使其位于 `SeekBar` 的上方。 ### 修改后的布局代码示例: ```xml <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_toRightOf="@id/divideLine"> <!-- 移除RelativeLayout的paddingBottom --> <com.scwang.smartrefresh.horizontal.SmartRefreshHorizontal android:id="@+id/refreshLayout" android:layout_width="match_parent" android:layout_height="match_parent" app:srlEnableFooterTranslationContent="true" app:srlEnableHeaderTranslationContent="true" app:srlEnablePreviewInEditMode="true"> <androidx.recyclerview.widget.RecyclerView android:id="@+id/rvApps" android:layout_width="match_parent" android:layout_height="match_parent" /> </com.scwang.smartrefresh.horizontal.SmartRefreshHorizontal> <!-- 将SeekBar放在底部,并调整SmartRefreshHorizontal的底部在SeekBar上方 --> <!-- 方法:在SmartRefreshHorizontal上设置底部margin,避免被SeekBar覆盖 --> <!-- 或者,将SmartRefreshHorizontal的高度设置为wrap_content,并设置above SeekBar --> <!-- 修改方案1:使用layout_above属性,让SmartRefreshHorizontal位于SeekBar上方 --> <!-- 首先给SeekBar设置id,然后让SmartRefreshHorizontal的底部在SeekBar顶部之上 --> <!-- 注意:需要调整SmartRefreshHorizontal的高度,不能是match_parent,而是使用layout_above --> <!-- 修改后的SmartRefreshHorizontal --> <com.scwang.smartrefresh.horizontal.SmartRefreshHorizontal android:id="@+id/refreshLayout" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_above="@id/app_progress" app:srlEnableFooterTranslationContent="true" app:srlEnableHeaderTranslationContent="true" app:srlEnablePreviewInEditMode="true"> <androidx.recyclerview.widget.RecyclerView android:id="@+id/rvApps" android:layout_width="match_parent" android:layout_height="match_parent" /> </com.scwang.smartrefresh.horizontal.SmartRefreshHorizontal> <androidx.appcompat.widget.AppCompatSeekBar android:id="@+id/app_progress" android:layout_width="@dimen/dp_100" android:layout_height="@dimen/dp_10" android:layout_centerHorizontal="true" android:layout_alignParentBottom="true" android:layout_marginBottom="@dimen/dp_21" android:maxHeight="@dimen/dp_10" android:maxWidth="@dimen/dp_100" android:max="100" android:min="1" android:thumb="@null" android:background="@null" style="@style/CustomSeekBarStyle" /> </RelativeLayout> ``` ### 解释: - 我们移除了 `RelativeLayout` 的 `paddingBottom`,避免占用底部空间。 - 将 `SmartRefreshHorizontal` 的高度设置为 `wrap_content`,并使用 `android:layout_above="@id/app_progress"` 使其底部位于 `SeekBar` 的顶部之上,这样 `SmartRefreshHorizontal` 就会占据从顶部到 `SeekBar` 顶部的空间。 - `SeekBar` 仍然固定在底部。 ### 替代方案:使用FrameLayout 如果使用 `FrameLayout`,可以更灵活地叠加视图,但需要手动设置 `SmartRefreshHorizontal` 的底部 `margin` 以避免被 `SeekBar` 覆盖。 ```xml <FrameLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_toRightOf="@id/divideLine"> <com.scwang.smartrefresh.horizontal.SmartRefreshHorizontal android:id="@+id/refreshLayout" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginBottom="@dimen/dp_31" <!-- 根据SeekBar的高度和margin调整,确保底部不被覆盖 --> app:srlEnableFooterTranslationContent="true" app:srlEnableHeaderTranslationContent="true" app:srlEnablePreviewInEditMode="true"> <androidx.recyclerview.widget.RecyclerView android:id="@+id/rvApps" android:layout_width="match_parent" android:layout_height="match_parent" /> </com.scwang.smartrefresh.horizontal.SmartRefreshHorizontal> <androidx.appcompat.widget.AppCompatSeekBar android:id="@+id/app_progress" android:layout_width="@dimen/dp_100" android:layout_height="@dimen/dp_10" android:layout_gravity="center_horizontal|bottom" android:layout_marginBottom="@dimen/dp_21" android:maxHeight="@dimen/dp_10" android:maxWidth="@dimen/dp_100" android:max="100" android:min="1" android:thumb="@null" android:background="@null" style="@style/CustomSeekBarStyle" /> </FrameLayout> ``` ### 注意事项: - 在 `FrameLayout` 中,`SeekBar` 会覆盖在 `SmartRefreshHorizontal` 上,所以需要给 `SmartRefreshHorizontal` 设置底部 `margin`,避免内容被 `SeekBar` 遮挡。 - 计算 `marginBottom` 的值:`SeekBar` 的高度(`@dimen/dp_10`)加上其 `layout_marginBottom`(`@dimen/dp_21`),可能需要设置 `@dimen/dp_31`(即10+21)或者根据实际情况调整。 ### 总结 通过调整布局参数,避免底部控件和边距的影响,即可让 `SmartRefreshHorizontal` 占满全屏(减去需要为 `SeekBar` 预留的空间)。根据实际需求选择使用 `RelativeLayout` 或 `FrameLayout` 的解决方案。 --- ### §§相关问题§§: 1. 在 `RelativeLayout` 中如何让一个视图位于另一个视图的上方? 2. 如何避免 `FrameLayout` 中的子视图相互遮挡? 3. `SmartRefreshLayout` 在滚动时如何避免与底部固定控件发生冲突? 4. 如何动态调整 `RecyclerView` 的底部边距以避免被底部控件遮挡?</think>### 解决 `SmartRefreshHorizontal` 在 `RelativeLayout` 中无法占满全屏的问题 在您提供的布局中,`SmartRefreshHorizontal` 被嵌套在 `RelativeLayout` 中,但存在两个关键问题导致无法全屏: 1. `RelativeLayout` 设置了 `android:paddingBottom="@dimen/dp_16"` 2. `AppCompatSeekBar` 固定在底部,覆盖了部分空间 以下是完整的解决方案: #### 修改后的布局代码 ```xml <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_toRightOf="@id/divideLine"> <!-- 移除父容器的paddingBottom --> <!-- 使用FrameLayout包裹刷新布局和SeekBar --> <FrameLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_above="@id/app_progress"> <!-- 关键:为SeekBar预留空间 --> <com.scwang.smartrefresh.horizontal.SmartRefreshHorizontal android:id="@+id/refreshLayout" android:layout_width="match_parent" android:layout_height="match_parent" app:srlEnableFooterTranslationContent="true" app:srlEnableHeaderTranslationContent="true" app:srlEnablePreviewInEditMode="true"> <androidx.recyclerview.widget.RecyclerView android:id="@+id/rvApps" android:layout_width="match_parent" android:layout_height="match_parent" /> </com.scwang.smartrefresh.horizontal.SmartRefreshHorizontal> </FrameLayout> <!-- 将SeekBar放在底部 --> <androidx.appcompat.widget.AppCompatSeekBar android:id="@+id/app_progress" android:layout_width="@dimen/dp_100" android:layout_height="@dimen/dp_10" android:layout_centerHorizontal="true" android:layout_alignParentBottom="true" android:layout_marginBottom="@dimen/dp_21" android:max="100" android:min="1" android:thumb="@null" android:background="@null" style="@style/CustomSeekBarStyle"/> </RelativeLayout> ``` #### 关键修改说明 1. **移除父容器内边距**: ```xml <!-- 移除这行 --> android:paddingBottom="@dimen/dp_16" ``` 2. **使用 FrameLayout 包裹 SmartRefreshHorizontal**: ```xml <FrameLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_above="@id/app_progress"> <!-- 确保在SeekBar上方 --> ``` 3. **添加布局约束**: - `android:layout_above="@id/app_progress"` 确保刷新布局在 SeekBar 上方 - `android:layout_alignParentBottom="true"` 固定 SeekBar 在底部 4. **可选:代码中动态调整高度** 如果布局仍然有问题,可在 Activity 中动态调整: ```java ViewTreeObserver.OnGlobalLayoutListener layoutListener = new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { refreshLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this); // 计算可用高度(减去SeekBar占用的空间) int seekBarHeight = appProgress.getHeight() + dpToPx(21); // 高度+margin int availableHeight = rootLayout.getHeight() - seekBarHeight; ViewGroup.LayoutParams params = refreshLayout.getLayoutParams(); params.height = availableHeight; refreshLayout.setLayoutParams(params); } private int dpToPx(int dp) { return (int) (dp * getResources().getDisplayMetrics().density); } }; refreshLayout.getViewTreeObserver().addOnGlobalLayoutListener(layoutListener); ``` #### 为什么这样修改有效? 1. **RelativeLayout 的特性**: - 子视图默认会重叠,需要明确指定位置关系 - `layout_above` 确保刷新布局不会延伸到 SeekBar 区域 2. **FrameLayout 的作用**: - 提供独立的绘制层 - 防止 SmartRefreshHorizontal 的测量被 SeekBar 影响 3. **尺寸计算**: - 明确区分内容区域和控件区域 - 使用 `match_parent` 结合约束而非固定尺寸 #### 备选方案:使用 ConstraintLayout 如果允许修改布局结构,更推荐使用 ConstraintLayout: ```xml <androidx.constraintlayout.widget.ConstraintLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_toRightOf="@id/divideLine"> <com.scwang.smartrefresh.horizontal.SmartRefreshHorizontal android:id="@+id/refreshLayout" android:layout_width="0dp" android:layout_height="0dp" app:layout_constraintTop_toTopOf="parent" app:layout_constraintBottom_toTopOf="@id/app_progress" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent" ...> <androidx.recyclerview.widget.RecyclerView android:layout_width="match_parent" android:layout_height="match_parent"/> </com.scwang.smartrefresh.horizontal.SmartRefreshHorizontal> <androidx.appcompat.widget.AppCompatSeekBar android:id="@+id/app_progress" android:layout_width="@dimen/dp_100" android:layout_height="@dimen/dp_10" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent" android:layout_marginBottom="@dimen/dp_21" .../> </androidx.constraintlayout.widget.ConstraintLayout> ``` ### 最终效果 - `SmartRefreshHorizontal` 将占据 SeekBar 之上的全部空间 - 垂直滚动时不会被底部控件遮挡 - 保持原有的下拉刷新/加载更多功能 --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

川峰

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值