简体   繁体   English

Android Studio-更改背景图片大小

[英]Android Studio - change background image size

So, i wanted to put an image in background of my screen. 因此,我想将图像放置在屏幕背景中。 My problem is that if i just add the image to "background" it will fill all the screen, and my image gets defaced. 我的问题是,如果我仅将图像添加到“背景”,它将填满所有屏幕,并且我的图像被污损。 I could put as an ImageView, but the problem is that i have an expandableListView in the same screen, and i wanted the image to stay behind, as a background. 我可以把它作为ImageView,但问题是我在同一屏幕上有一个expandableListView,并且我希望图像留在背景上。 Any idea how to do this? 任何想法如何做到这一点? Can have 2 solutions: Put as an imagemView but behind the list. 可以有2个解决方案:作为imagemView放置在列表后面。 Or add as a background but resize it. 或添加为背景但调整其大小。 How can i do it? 我该怎么做?

Here is what happened: 这是发生了什么:

在此处输入图片说明

He is what happens if i put the image as an imageView: 如果我将图像作为imageView会发生什么呢?

在此处输入图片说明

Yes this is very easy to achieve with relative layouts 是的,使用相对布局非常容易实现

<RelativeLayout ... > 
    <ImageView ... 
            android:layout_alignParentTop="true"
            android:scaleType="centerCrop“ /> 
    <ListView ... 
            android:layout_alignParentTop="true“ /> 
</RelativeLayout>

With a relative layout z-index is decided by the order you declare the tags, so stuff towards the bottom of the xml is in front of stuff from closer to the top, when they are in the same position. 使用相对布局时,z-index由声明标签的顺序决定,因此,当xml底部的内容位于相同位置时,它们的位置在顶部附近,而顶部位置从顶部到顶部。

Use a FrameLayout (Inside FrameLayout view written on top will appear on top and so on) 使用FrameLayout(写在顶部的内部FrameLayout视图将显示在顶部,依此类推)

<FrameLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">

<ListView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    ></ListView>


<ImageView
    android:layout_width="your_width_in_dp"
    android:layout_height="your_height_in_dp"
    />

</FrameLayout>

You can also place FrameLayout inside another layout. 您也可以将FrameLayout放置在另一个布局中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM