20251203_211951_581BackgroundView 。布局文件调整。。。
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
#Created by .winboll/winboll_app_build.gradle
|
#Created by .winboll/winboll_app_build.gradle
|
||||||
#Wed Dec 03 12:54:41 GMT 2025
|
#Wed Dec 03 13:18:48 GMT 2025
|
||||||
stageCount=13
|
stageCount=13
|
||||||
libraryProject=
|
libraryProject=
|
||||||
baseVersion=15.11
|
baseVersion=15.11
|
||||||
publishVersion=15.11.12
|
publishVersion=15.11.12
|
||||||
buildCount=139
|
buildCount=140
|
||||||
baseBetaVersion=15.11.13
|
baseBetaVersion=15.11.13
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ import java.io.File;
|
|||||||
import android.widget.ImageView.ScaleType;
|
import android.widget.ImageView.ScaleType;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
import cc.winboll.studio.powerbell.R;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author ZhanGSKen&豆包大模型<zhangsken@qq.com>
|
* @Author ZhanGSKen&豆包大模型<zhangsken@qq.com>
|
||||||
@@ -29,6 +31,7 @@ public class BackgroundView extends RelativeLayout {
|
|||||||
|
|
||||||
// 上下文对象(全局复用)
|
// 上下文对象(全局复用)
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
|
private LinearLayout mllMain;
|
||||||
// 背景图片显示控件(核心子View)
|
// 背景图片显示控件(核心子View)
|
||||||
private ImageView mivBackground;
|
private ImageView mivBackground;
|
||||||
// 背景资源工具类(单例实例,避免重复创建)
|
// 背景资源工具类(单例实例,避免重复创建)
|
||||||
@@ -95,15 +98,20 @@ public class BackgroundView extends RelativeLayout {
|
|||||||
*/
|
*/
|
||||||
private void initView() {
|
private void initView() {
|
||||||
LogUtils.d(TAG, "=== initView(视图初始化)启动 ===");
|
LogUtils.d(TAG, "=== initView(视图初始化)启动 ===");
|
||||||
|
|
||||||
|
//mllMain = inflate(mContext, R.layout.view_background, null);
|
||||||
|
// mllMain.setBackgroundColor(0x00000000); // 全透明背景(ARGB:透明通道+黑色,无视觉影响)
|
||||||
|
// mllMain.setBackground(new ColorDrawable(0x00000000)); // 双重保障:兼容Android低版本,确保背景透明
|
||||||
|
//
|
||||||
// 1. 配置当前控件:完全填充父视图 + 全透明背景 + 无内边距
|
// 1. 配置当前控件:完全填充父视图 + 全透明背景 + 无内边距
|
||||||
setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
|
// setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
|
||||||
setPadding(0, 0, 0, 0); // 取消自身内边距,避免父容器与控件间出现缝隙
|
// setPadding(0, 0, 0, 0); // 取消自身内边距,避免父容器与控件间出现缝隙
|
||||||
setBackgroundColor(0x00000000); // 全透明背景(ARGB:透明通道+黑色,无视觉影响)
|
// setBackgroundColor(0x00000000); // 全透明背景(ARGB:透明通道+黑色,无视觉影响)
|
||||||
setBackground(new ColorDrawable(0x00000000)); // 双重保障:兼容Android低版本,确保背景透明
|
// setBackground(new ColorDrawable(0x00000000)); // 双重保障:兼容Android低版本,确保背景透明
|
||||||
|
//
|
||||||
// 2. 初始化背景资源工具类(单例模式,全局唯一实例)
|
// // 2. 初始化背景资源工具类(单例模式,全局唯一实例)
|
||||||
mBackgroundSourceUtils = BackgroundSourceUtils.getInstance(mContext);
|
// mBackgroundSourceUtils = BackgroundSourceUtils.getInstance(mContext);
|
||||||
|
//
|
||||||
// 3. 初始化内部ImageView(背景图片显示核心控件)
|
// 3. 初始化内部ImageView(背景图片显示核心控件)
|
||||||
initBackgroundImageView();
|
initBackgroundImageView();
|
||||||
|
|
||||||
@@ -118,22 +126,27 @@ public class BackgroundView extends RelativeLayout {
|
|||||||
*/
|
*/
|
||||||
private void initBackgroundImageView() {
|
private void initBackgroundImageView() {
|
||||||
LogUtils.d(TAG, "=== initBackgroundImageView(内部ImageView初始化)启动 ===");
|
LogUtils.d(TAG, "=== initBackgroundImageView(内部ImageView初始化)启动 ===");
|
||||||
mivBackground = new ImageView(mContext);
|
mllMain = (LinearLayout)inflate(mContext, R.layout.view_background, null);
|
||||||
|
mllMain.setBackgroundColor(0x00000000); // 全透明背景(ARGB:透明通道+黑色,无视觉影响)
|
||||||
|
mllMain.setBackground(new ColorDrawable(0x00000000)); // 双重保障:兼容Android低版本,确保背景透明
|
||||||
|
|
||||||
|
mivBackground = mllMain.findViewById(R.id.bg_imageview);
|
||||||
|
//mivBackground = new ImageView(mContext);
|
||||||
// 配置ImageView布局参数:宽高自适应 + 居中显示 + 无内边距/外边距
|
// 配置ImageView布局参数:宽高自适应 + 居中显示 + 无内边距/外边距
|
||||||
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
|
// RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
|
||||||
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
// LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
||||||
layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT); // 核心:让ImageView在当前控件中居中
|
// layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT); // 核心:让ImageView在当前控件中居中
|
||||||
layoutParams.setMargins(0, 0, 0, 0); // 取消外边距,避免ImageView与控件间出现缝隙
|
// layoutParams.setMargins(0, 0, 0, 0); // 取消外边距,避免ImageView与控件间出现缝隙
|
||||||
mivBackground.setLayoutParams(layoutParams);
|
// mivBackground.setLayoutParams(layoutParams);
|
||||||
|
|
||||||
// 配置ImageView显示属性:保持比例 + 全透明背景
|
// 配置ImageView显示属性:保持比例 + 全透明背景
|
||||||
mivBackground.setScaleType(ImageView.ScaleType.FIT_CENTER); // 缩放模式:保持比例,完整显示图片
|
mivBackground.setScaleType(ImageView.ScaleType.FIT_CENTER); // 缩放模式:保持比例,完整显示图片
|
||||||
mivBackground.setPadding(0, 0, 0, 0); // 取消内边距,避免图片与ImageView间出现缝隙
|
//mivBackground.setPadding(0, 0, 0, 0); // 取消内边距,避免图片与ImageView间出现缝隙
|
||||||
mivBackground.setBackgroundColor(0x00000000); // ImageView自身背景全透明
|
//mivBackground.setBackgroundColor(0x00000000); // ImageView自身背景全透明
|
||||||
mivBackground.setBackground(new ColorDrawable(0x00000000)); // 低版本兼容,确保透明
|
//mivBackground.setBackground(new ColorDrawable(0x00000000)); // 低版本兼容,确保透明
|
||||||
|
|
||||||
// 将ImageView添加到当前控件(父容器)
|
// 将ImageView添加到当前控件(父容器)
|
||||||
this.addView(mivBackground);
|
this.addView(mllMain);
|
||||||
LogUtils.d(TAG, "=== initBackgroundImageView(内部ImageView初始化)完成 ===");
|
LogUtils.d(TAG, "=== initBackgroundImageView(内部ImageView初始化)完成 ===");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
15
powerbell/src/main/res/layout/view_background.xml
Normal file
15
powerbell/src/main/res/layout/view_background.xml
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:id="@+id/bg_main">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:id="@+id/bg_imageview"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
Reference in New Issue
Block a user