小编cha*_*hma的帖子

以编程方式更改ConstraintLayout子项的边距和大小

我正在编写一个自定义视图,以便能够使用自定义XML属性根据这些属性设置视图的边距和大小,一切正常,直到我到达ConstraintLayout的子项获得其边距和大小由自定义值确定的部分.边距没有任何区别,视图保留在其父ConstraintLayout的左上角.可能是什么问题呢?(图像应距离屏幕边界500PXs)

if (hasCustomWidth || hasCustomHeight || hasCustomTopMargin || hasCustomRightMargin || hasCustomBottomMargin || hasCustomLeftMargin) {
    if(((ViewGroup)getParent()) instanceof  LinearLayout) {
        LinearLayout.LayoutParams newLayoutParams = new LinearLayout.LayoutParams((int) Math.round(customWidth), (int) Math.round(customHeight));
        ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) newLayoutParams;
        marginLayoutParams.setMargins((int) Math.round(customLeftMargin), (int) Math.round(customTopMargin), (int) Math.round(customRightMargin), (int) Math.round(customBottomMargin));
        setLayoutParams(newLayoutParams);
    } else if(((ViewGroup)getParent()) instanceof ConstraintLayout) {
        ConstraintLayout parentConstraintLayout = (ConstraintLayout)CustomAppCompatImageView.this.getParent();

        ConstraintLayout.LayoutParams newLayoutParams = new ConstraintLayout.LayoutParams((int) Math.round(customWidth), (int) Math.round(customHeight));

        ConstraintSet constraintSet = new ConstraintSet();

        constraintSet.clone(parentConstraintLayout);

        constraintSet.connect(CustomAppCompatImageView.this.getId(), ConstraintSet.LEFT, ConstraintSet.PARENT_ID, ConstraintSet.LEFT, 500);
        constraintSet.setMargin(CustomAppCompatImageView.this.getId(), ConstraintSet.LEFT, 500);

        setLayoutParams(newLayoutParams);
        constraintSet.applyTo(parentConstraintLayout);

        parentConstraintLayout.invalidate();
    } else {
        throw new …
Run Code Online (Sandbox Code Playgroud)

android android-custom-attributes android-constraintlayout

13
推荐指数
1
解决办法
4298
查看次数

Android SDK 是编译/链接到 APK 还是安装在 Android 设备上?

首先是一些前提:

  1. Android 应用程序使用 Android SDK API 类。

  2. 类定义是一些代码或代码的一部分,它被编译成机器代码/字节码。

  3. 我假设构成 Android SDK API 的所有(或大部分)类/包都列在:
    https : //developer.android.com/reference/packages.html https://developer.android.com/reference/ classes.html 里面

    有很多!


现在的问题是:

这些代码/数据位于何处?它们是与应用程序代码一起编译到 APK 文件中还是存在于设备上的 Android 操作系统中,在这种情况下,应用程序应该动态链接到它们?

如果它们存在于设备上,那么使用较新的 Android SDK 版本(例如,Android Studio 中的每个 compileSdkVersion)编译应用程序有什么区别?

假设“Android SDK 构建工具”(与“SDK 平台”不同(根据“SDK 管理器”窗口!)并且有自己的版本控制)负责编译您的代码,因此较新的版本意味着更好的字节码优化和更快的 JAVA -> DEX 翻译!? 构建/编译工具

您编译 Android 应用程序并使用 compileSdkVersion 关键字设置其版本的“SDK 平台”是否仅包含类声明和引用符号?! 安卓SDK

Google API(例如 Google Maps API)呢?

Android 支持库怎么样?

android google-api android-studio android-sdk-manager

7
推荐指数
1
解决办法
396
查看次数

如何在程序中包含数据对象文件(图像等)并访问符号?

我已经将几个资源文件转换为.obj文件objcopy,并将它们与我的程序源代码链接起来.我可以使用以下代码很好地访问程序中目标文件内的符号,但只能使用GCC/G ++(Cygwin):

extern uint8_t data[]   asm("_binary_Resources_0_png_start");
extern uint8_t size[]   asm("_binary_Resources_0_png_size");
extern uint8_t end[]    asm("_binary_Resources_0_png_end");
Run Code Online (Sandbox Code Playgroud)

该代码在Visual Studio中不起作用,可能是因为VS拥有自己的__asm命令.我希望.data通过链接它们将我的程序资源(图像,着色器等)包含在我的最终可执行文件部分中.

但是如何在VC++中访问目标文件中定义的符号?我尝试了extern uint8_t _binary_Resources_0_png_start[]extern "C" uint8_t _binary_Resources_0_png_start[]没有汇编命令,但我得到了未解决的符号链接错误.

c c++ assembly linker undefined-reference

7
推荐指数
3
解决办法
2216
查看次数

Using different texture types in same texture unit at the same time in shader

I came across a nasty problem in my program when i tried to use the same texture unit (number 0) for different texture types (i.e. a normal 2D texture and a cube map) in my shader. It appeared so that the GL issues a 502H (Invalid Operation) after the first glDrawArrays call. In my application code i load up the textures to different texture targets:

void setup_textures()
{
    unsigned int width, height;
    int components;
    unsigned int format;
    float param[8];
    vector<unsigned …
Run Code Online (Sandbox Code Playgroud)

c++ opengl textures glsl opengl-3

6
推荐指数
1
解决办法
1540
查看次数

Vulkan纹理模糊问题

我有一个简单的Vulkan设置,可以加载一个非常大的网格文件(女人),还可以应用漫反射和法线贴图.

顶点着色器:

#version 450 core

layout (set = 0, binding = 0) uniform ModelMatrix {
    mat4 model;
} modelMatrix;

layout (push_constant) uniform ViewProjection {
    mat4 view;
    mat4 projection;
} viewProjection;

layout (location = 0) in vec3 inPos;

layout (location = 1) in vec3 inNor;

layout (location = 2) in vec2 inUV;

layout (location = 3) in vec3 inTan;

layout (location = 4) in vec3 inBitan;

layout (location = 0) out vec3 fragPos;

layout (location = 1) out vec2 fragUV;

layout …
Run Code Online (Sandbox Code Playgroud)

shader textures vulkan

5
推荐指数
1
解决办法
210
查看次数

访问者关键字的“保真度”是什么意思?

我正在阅读.Net Docs,遇到了“保真度”这个词,

类型安全性还用于通过保证访问者关键字的保真度来帮助强制执行封装。

这是什么意思(相对于访问者关键字)?

c# encapsulation accessor

5
推荐指数
1
解决办法
318
查看次数

asp-for 标签帮助器功能

我知道asp-foran 的标签助手<input>设置name属性,以便它可以绑定到模型类。例如asp-for="Movie.Year",当从 POST 请求检索数据时...

在另一种情况下(可能是 GET 请求):还从模型类实例中asp-for提取每个s 值,并在通过 PageModel 派生类实例化后基于它填充属性。<input>value

例如

<input asp-for="Movie.Price" class="form-control" />
Run Code Online (Sandbox Code Playgroud)

asp.net razor tag-helpers asp.net-core

5
推荐指数
0
解决办法
1万
查看次数

@model 到底做了什么?

每当我将@model [Type]其放在 Razor 页面顶部时,某些泛型类型和方法的类型参数都会解析为 [Type],例如:

string DisplayNameFor<TResult>(Expression<Func<TModel, TResult>> expression);
Run Code Online (Sandbox Code Playgroud)

变成

string DisplayNameFor<TResult>(Expression<Func<[Type], TResult>> expression);
Run Code Online (Sandbox Code Playgroud)

ASP.NET Core 如何实现这一目标?type参数如何TModel变成[Type]?

asp.net asp.net-mvc asp.net-core

3
推荐指数
1
解决办法
2621
查看次数