如果您想了解android-通知高度不正确的“match_parent”和通知栏高度修改的知识,那么本篇文章将是您的不二之选。我们将深入剖析android-通知高度不正确的“match_parent”
如果您想了解android-通知高度不正确的“ match_parent”和通知栏高度修改的知识,那么本篇文章将是您的不二之选。我们将深入剖析android-通知高度不正确的“ match_parent”的各个方面,并为您解答通知栏高度修改的疑在这篇文章中,我们将为您介绍android-通知高度不正确的“ match_parent”的相关知识,同时也会详细的解释通知栏高度修改的运用方法,并给出实际的案例分析,希望能帮助到您!
本文目录一览:- android-通知高度不正确的“ match_parent”(通知栏高度修改)
- Android 2.2 中match_parent和fill_parent是一个意思
- Android Chrome CanvasRenderingContext2D 画布比例不正确
- Android Composable - PreviewView 上的宽度/高度不正确
- Android fill_parent、wrap_content 和 match_parent 的区别
android-通知高度不正确的“ match_parent”(通知栏高度修改)
我尝试使用此xml代码创建自定义视图:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FF0000">
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/ic_launcher"/>
</LinearLayout>
我用以下代码运行通知:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.notification_layout);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setContent(remoteViews).setSmallIcon(R.drawable.ic_launcher);
notificationmanager mnotificationmanager =
(notificationmanager) getSystemService(Context.NOTIFICATION_SERVICE);
mnotificationmanager.notify(20, mBuilder.build());
}
结果如下:
为什么“ match_parent”不使用通知的全部高度?
我希望红色区域的高度与通知的高度相同,而不使用“ dip”统一.我使用的是Android 4.2.2.谢谢 !
解决方法:
您是否尝试过使用RelativeLayout?并在ImageView标签中使用这些属性
android:scaleType="centerCrop"
android:adjustViewBounds="true"
Android 2.2 中match_parent和fill_parent是一个意思
标题里已经把这个意思表达清楚了,两个参数意思一样,只是某大仙觉得match_parent更贴切,于是从2.2开始你两个词都可以用。那么如果考虑低版本的使用情况你就需要用fill_parent了。
下面是两者相同的证据,看android.view.ViewGroup里的静态嵌套类LayoutParams中的代码:
public static final int FILL_PARENT = -1; /** * Special value for the height or width requested by a View. * MATCH_PARENT means that the view wants to be as big as its parent, * minus the parent''s padding, if any. Introduced in API Level 8. */ public static final int MATCH_PARENT = -1; /** * Special value for the height or width requested by a View. * WRAP_CONTENT means that the view wants to be just large enough to fit * its own internal content, taking its own padding into account. */
Android Chrome CanvasRenderingContext2D 画布比例不正确
如何解决Android Chrome CanvasRenderingContext2D 画布比例不正确?
我正在尝试让一款在 HTML 5 画布中运行的游戏在所有设备上看起来都一样,而且我已经完成了大部分工作。游戏通常会调整自身大小以填充 100% 的可用高度或 100% 的可用宽度(以更好的为准),同时保持 9:16 的纵横比。但是,某些在 Chrome 上浏览页面的 Android 移动设备无法正确缩放画布内容。部分画布内容未显示在屏幕上,导致无法玩游戏。
MindmetriQ displaying correctly
MindmetriQ displaying incorrectly(注意右边的7是不可见的,而且底部的按钮也不是明显的按钮,导致一般用户认为游戏没有反应)
浏览器不显示滚动条的事实意味着画布本身正确填充了可用空间,它必须是无法正常工作的 CanvasRenderingContext2D 缩放。只有 Android Chrome 表现出这种行为,并且仅适用于某些设备。通过浏览 browserstack 上的设备/浏览器组合列表(不要与 browserSack 混淆),我发现它在这些组合上显示不正确:
- OnePlus 8 - 铬
- 摩托罗拉 Moto G7 Play - Chrome
- 小米红米 Note 9 - 铬
- Oppo Reno 3 Pro - 铬
在测试各种设备/浏览器组合时,我并未详尽无遗,但我确实在每个可用制造商的设备上尝试了所有可用浏览器。此外,我的同事(以及我们的一些实际用户)使用真实设备发现了其他具有相同行为的组合,主要是 Android Chrome。我们从未在台式机或平板电脑上重现此问题,iOS 手机也很少重现。
该游戏套件名为 MindmetriQ,并已部署到生产环境 here。 (MindmetriQ 套件中还有 5 个其他游戏受到同样的影响,但这款游戏最能说明问题。)游戏本身是用 TypeScript 编写的,我们将其嵌入到 ASP .Net MVC 页面中。
TypeScript (event-listener.ts):
private scaleCanvasToAvailableSpace(maxAvailableWidth: number,maxAvailableHeight: number): void {
//Anything in all caps is a number constant defined in constants.ts
const nativeAspectRatio = CANVASWIDTH / CANVASHEIGHT;
const currentAspectRatio = maxAvailableWidth / maxAvailableHeight;
let desiredWidth: number;
let desiredHeight: number;
if (currentAspectRatio > nativeAspectRatio) {
desiredHeight = maxAvailableHeight;
desiredWidth = desiredHeight * nativeAspectRatio;
} else {
desiredWidth = maxAvailableWidth;
desiredHeight = desiredWidth / nativeAspectRatio;
}
//Performance improvement to prevent resizing when dimensions have barely (or not) changed
if (Math.abs(this._canvas.width - desiredWidth) > 0.25) {
this._canvasScale.x = desiredWidth / CANVASWIDTH;
this._canvasScale.y = desiredHeight / CANVASHEIGHT;
//_canvas is the HTMLCanvasElement
this._canvas.width = desiredWidth;
this._canvas.height = desiredHeight;
//S_Context is the CanvasRenderingContext2D for the canvas
//_canvasScale is just a holder of two numbers,x & y,for use when we draw on the canvas
S_Context.scale(this._canvasScale.x,this._canvasScale.y);
//S_AccessibilityHandler is a custom accessibility framework that builds divs,//associates them with things in the canvas,and moves the divs around
//whenever the corresponding thing moves.
//They''re designed to be visible to screen readers only.
//This has caused a lot of bugs in the past,but usually by stretching the viewport too wide
S_AccessibilityHandler.setoffset(this._canvas.offsetLeft,this._canvas.offsetTop);
}
}
window.onresize = (event: UIEvent) => {
this.scaleCanvasToAvailableSpace(window.innerWidth,window.innerHeight);
};
this.scaleCanvasToAvailableSpace(window.innerWidth,window.innerHeight);
//Hack to handle how some mobile browsers believe that an address bar is part of the inner window,//even though it clearly isn''t
//We recalculate the available height after the browser has finished sliding in the address bar
//This causes a flash 1 second after the page loads on certain browsers
//This fix is for an entirely separate canvas resizing bug
//where the canvas content was overflowing off the bottom of the window,//and the overflow height was always equal to the address bar height
setTimeout(() => {
this.scaleCanvasToAvailableSpace(window.innerWidth,window.innerHeight);
},1000);
CSHTML:
@model TestPartnership.Web.Controllers.viewmodels.Mindmetriq.InitialLoadviewmodel
@using System.Globalization
@using System.Web.Optimization
@using TestPartnership.Core.Helpers
@using TestPartnership.Localisation
@using TestPartnership.Web.Utilities
@{
Layout = null;
var skin = SessionManager.GetSkin();
var favIconPath = skin == null ? "/Content/Images/favicon.png" : skin.FavIconPath;
}
<html lang="@SessionManager.GetLanguage().GetHtmlLangAttribute()">
<head>
<Meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>@Model.Title</title>
<Meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<Meta name="viewport" content="width=device-width,initial-scale=1.0 maximum-scale=1.0" />
<link rel="shortcut icon" sizes="32x32" href="@favIconPath" />
@*----Apple Junk Start----*@
<link rel="apple-touch-icon" href="@favIconPath" />
<link rel="apple-touch-icon" sizes="120x120" href="@favIconPath" />
<link rel="apple-touch-icon" sizes="152x152" href="@favIconPath" />
<link rel="apple-touch-icon-precomposed" sizes="120x120" href="@favIconPath" />
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="@favIconPath" />
@*------Apple Junk End------*@
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
<link href="~/Styles/Framework/mindmetriq-base.css" rel="stylesheet">
</head>
<body>
<canvas id="mindmetriq" width="459" height="816">@TranslationHelper.CandidateMindmetriqHtml5Message</canvas>
@Scripts.Render("~/MindmetriQ")
<script>
window.onload = (function() {
// ReSharper disable once USEOfImplicitGlobalInFunctionScope
window.mindmetriq = new Main("@Model.Name","@(Model.Language)","@(Model.BaseSubmitUrl)","@(Model.BaseAssetUrl)",@(Model.AssessmentSectionId),@(Model.SkipTutorial.ToJsstring()),@(Model.ExtraTimeFactor.ToString("F2",CultureInfo.InvariantCulture))
@if (Model.TimeBoostsRecordedOnServer.HasValue)
{
<text>,</text>@(Model.TimeBoostsRecordedOnServer.Value)
}
@if (Model.BoostRecordedForCurrentQuestion.HasValue)
{
<text>,</text>@(Model.BoostRecordedForCurrentQuestion.Value.ToJsstring())
}
);
window.mindmetriq.run();
});
</script>
</body>
</html>
CSS:
body,html {
touch-action: manipulation;
font-family: ''Roboto'';
width: 100%;
height: 100%;
margin: 0;
padding: 0;
overflow: hidden;
}
canvas {
background-color: #f2f2f2;
border: 1px solid #78909c;
position: absolute;
left: 0;
right: 0;
margin: 0 auto;
padding: 0;
-ms-touch-action: pinch-zoom;
touch-action: pinch-zoom;
}
div.mindmetriq-accessibility {
position: absolute;
background: transparent;
pointer-events: none;
touch-action: none;
}
您知道为什么某些浏览器(而不是其他浏览器)无法正确缩放画布内容吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
Android Composable - PreviewView 上的宽度/高度不正确
如何解决Android Composable - PreviewView 上的宽度/高度不正确?
目前正在使用 Composable 为 CameraX 构建 PreviewView。但是,正如您在图像中看到的,实际视图没有正确渲染,需要多次切换相机才能正确渲染。为什么是这样?我附上了我的源代码以供参考。
Incorrect width and height
class CameraPreview {
private var cameraProvider: ProcessCameraProvider? = null
private var lensFacing: Int = CameraSelector.LENS_FACING_BACK
private var camera: Camera? = null
private lateinit var displayManager: displayManager
private var preview: Preview? = null
@RequiresApi(Build.VERSION_CODES.R)
@Composable
fun displayCamera() {
val context = LocalContext.current
val lifecycleOwner = LocalLifecycleOwner.current
val cameraProviderFuture = remember { ProcessCameraProvider.getInstance(context) }
displayManager = context.getSystemService(Context.disPLAY_SERVICE) as displayManager
lateinit var previewView: PreviewView
var executor: Executor
Scaffold(topBar = { },floatingActionButton = {
FloatingActionButton(
onClick = {
lensFacing = if (CameraSelector.LENS_FACING_FRONT == lensFacing) {
CameraSelector.LENS_FACING_BACK
} else {
CameraSelector.LENS_FACING_FRONT
}
bindCameraUseCases(previewView,lifecycleOwner,context)
},modifier = Modifier.padding(20.dp)
) {
Icon(Icons.Default.SwitchCamera,"")
}
},content = {
AndroidView(modifier = Modifier.fillMaxSize(),factory = { _context ->
previewView = PreviewView(_context)
executor = ContextCompat.getMainExecutor(_context)
cameraProviderFuture.addListener({
cameraProvider = cameraProviderFuture.get()
lensFacing = when {
hasBackCamera() -> CameraSelector.LENS_FACING_BACK
hasFrontCamera() -> CameraSelector.LENS_FACING_FRONT
else -> throw IllegalStateException("Back and front camera are unavailable")
}
bindCameraUseCases(previewView,context)
},ContextCompat.getMainExecutor(context))
previewView
})
}
)
}
@RequiresApi(Build.VERSION_CODES.R)
private fun bindCameraUseCases(previewView: PreviewView,lifecycleOwner: LifecycleOwner,context: Context) {
val metrics: displayMetrics = context.getResources().getdisplayMetrics()
val screenAspectRatio = aspectRatio(metrics.widthPixels,metrics.heightPixels)
val rotation = displayManager.displays[0].rotation
val cameraProvider = cameraProvider
?: throw IllegalStateException("Camera initialization Failed.")
val cameraSelector = CameraSelector.Builder().requireLensFacing(lensFacing).build()
preview = Preview.Builder()
.setTargetAspectRatio(screenAspectRatio)
.setTargetRotation(rotation)
.build()
cameraProvider.unbindAll()
try {
camera = cameraProvider.bindToLifecycle(
lifecycleOwner,cameraSelector,preview)
preview?.setSurfaceProvider(previewView.surfaceProvider)
} catch (exc: Exception) {
Log.e("PEOPLE DETECTOR","Use case binding Failed",exc)
}
}
private fun aspectRatio(width: Int,height: Int): Int {
val previewRatio = max(width,height).todouble() / min(width,height)
if (abs(previewRatio - RATIO_4_3_VALUE) <= abs(previewRatio - RATIO_16_9_VALUE)) {
return AspectRatio.RATIO_4_3
}
return AspectRatio.RATIO_16_9
}
private fun hasBackCamera(): Boolean {
return cameraProvider?.hasCamera(CameraSelector.DEFAULT_BACK_CAMERA) ?: false
}
private fun hasFrontCamera(): Boolean {
return cameraProvider?.hasCamera(CameraSelector.DEFAULT_FRONT_CAMERA) ?: false
}
companion object {
private const val RATIO_4_3_VALUE = 4.0 / 3.0
private const val RATIO_16_9_VALUE = 16.0 / 9.0
}
}
您是否看到任何可能导致问题的原因?这让我难以置信。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
Android fill_parent、wrap_content 和 match_parent 的区别
三个属性都用来适应视图的水平或垂直大小,一个以视图的内容或尺寸为基础的布局比精确地指定视图范围更加方便。
1)fill_parent
设置一个构件的布局为 fill_parent 将强制性地使构件扩展,以填充布局单元内尽可能多的空间。这跟 Windows 控件的 dockstyle 属性大体一致。设置一个顶部布局或控件为 fill_parent 将强制性让它布满整个屏幕。
2) wrap_content
设置一个视图的尺寸为 wrap_content 将强制性地使视图扩展以显示全部内容。以 TextView 和 ImageView 控件为例,设置为 wrap_content 将完整显示其内部的文本和图像。布局元素将根据内容更改大小。设置一个视图的尺寸为 wrap_content 大体等同于设置 Windows 控件的 Autosize 属性为 True。
3)match_parent
Android2.2 中 match_parent 和 fill_parent 是一个意思。两个参数意思一样,match_parent 更贴切,于是从 2.2 开始两个词都可以用。那么如果考虑低版本的使用情况你就需要用 fill_parent 了
今天的关于android-通知高度不正确的“ match_parent”和通知栏高度修改的分享已经结束,谢谢您的关注,如果想了解更多关于Android 2.2 中match_parent和fill_parent是一个意思、Android Chrome CanvasRenderingContext2D 画布比例不正确、Android Composable - PreviewView 上的宽度/高度不正确、Android fill_parent、wrap_content 和 match_parent 的区别的相关知识,请在本站进行查询。
本文标签: