设置背景图像视图绵延我的看法视图、我的看法、图像、背景

2023-09-12 09:33:17 作者:TRANSFORMER(变形女)

我创建背景图像位图的图,现在该视图被拉伸到背景图像的大小....

这正常吗?

 < XML版本=1.0编码=UTF-8&GT?;
    <位图的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
        机器人:SRC =@可绘制/绿
        机器人:TILEMODE =重复/>
 

下面是我如何将其应用到我的观点

  v.setBackgroundResource(R.drawable.backgroundgreen);
 
在PRO E里的视图里的颜色和外观里怎样添加自己想要的图片进去

比如...

如果图像是高度500px的 和视图中,高度200像素(被设置WRAP_CONTENT为高) 设置图像作为背景后,我的看法变得500px的高度...

解决方案

据我,你所面临的问题不是一个问题,那是多么的Andr​​oid被用于设计布局的方式。

这意味着,你可以设置高度和宽度与3默认常数值:

FILL_PARENT 对于由查看要求的高度或宽度特殊价值。 FILL_PARENT 意味着视图想要成为大如其父,减去母公司的填充(如有)。这个值去precated开始在API级别8,取而代之的是 MATCH_PARENT

MATCH_PARENT 对于由查看要求的高度或宽度特殊价值。 MATCH_PARENT 意味着视图想要成为大如其父,减去母公司的填充(如有)。在API级别8中引入的。

WRAP_CONTENT 对于由查看要求的高度或宽度特殊价值。 WRAP_CONTENT 表示查看要刚好足够大,以适应其自身内部的含量,走自己的填充进去

现在,当你设置查看的高度/宽度 WRAP_CONTENT ,您允许的看法采取这种多大小是足以说明,以查看的内容。背景图片也是查看的内容,因此,您可以查看将显示尽可能多尺寸的图像来。这不是一个问题,那就是它是如何显示。

好了,但在你的情况是你的问题,因为你有一个背景,以显示和查看不应该被拉伸了点。我可以建议一些方法:

首先,很明显的:使正常大小的图像,并让他们在不同的绘制文件夹

指定的视图不使用尺寸constants,但在 DP 。如果有必要,做出不同的布局XML文件不同的大小和保持他们在布局文件夹。

您可以使用设计布局非常有用的东西是布局重量。

I created a background image bitmap for a view and now the view is being stretched to the size of the background image....

is this normal?

<?xml version="1.0" encoding="utf-8"?>
    <bitmap xmlns:android="http://schemas.android.com/apk/res/android"
        android:src="@drawable/green"
        android:tileMode="repeat"/>

here's how I apply it to my view

v.setBackgroundResource(R.drawable.backgroundgreen);

for instance...

if the image is 500px in height and the view is 200px in height(being set wrap_content as height) after setting the image as background my view becomes 500px in height...

解决方案

According to me, the problem you are facing is not a problem, it is the way how Android is used to design the layouts.

This means that you can set the height and width with 3 default constant values:

FILL_PARENT Special value for the height or width requested by a View. FILL_PARENT means that the View wants to be as big as its parent, minus the parent's padding if any. This value is deprecated starting in API Level 8 and replaced by MATCH_PARENT.

MATCH_PARENT 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.

WRAP_CONTENT 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.

Now, when you are setting the View's height/width to WRAP_CONTENT, you are allowing the view to take that much size that is sufficient to show to view's content. The background image is also the View's content, hence you view will be shown of as much size as the image. That's not a problem, that's how it's shown.

Okay, but in your situation that's an issue for you because you have a background to show and view should not be stretched for that. I can suggest few ways:

First and very obvious: make correctly sized images and keep them in different drawable folders.

Specify the size of view not using constants, but in DP. If it becomes necessary, make different layout XML files for different sizes and keep them in layout folders.

You can use a very useful thing for design layout is layout weight.