首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用可绘制文件夹来适应背景图像

如何使用可绘制文件夹来适应背景图像
EN

Stack Overflow用户
提问于 2014-03-20 09:40:52
回答 3查看 526关注 0票数 0

我正在使用API 16 (Jellybean),4.0 WVGA (480x800: hdpi)

我试图在背景中设置一个480x800图像

我把一个图像放在“drawable hdpi”中,但是这个图像不适合背景,为什么当我使用4.0 WVGA (480x800: hdpi)并且与图像大小相同时,这个图像不适合背景。

如何绘制适合图像的工作方式:

这是我的代码:

代码语言:javascript
运行
复制
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.newapp.Firstscreen$PlaceholderFragment" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:src="@drawable/background" />

</RelativeLayout>

见截图:

http://s15.postimg.org/u8rkm6rhn/frghfghfgh.png

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2014-03-20 09:44:39

你可以这样做

代码语言:javascript
运行
复制
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"     
    tools:context="com.example.newapp.Firstscreen$PlaceholderFragment" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_paren"
        android:layout_height="match_paren"
        android:scaleType="fitXY"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:src="@drawable/background" />

</RelativeLayout>

代码语言:javascript
运行
复制
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        android:background="@drawable/background"
        tools:context="com.example.newapp.Firstscreen$PlaceholderFragment" >
<!-- CONTENT HERE -->
</RelativeLayout>
票数 1
EN

Stack Overflow用户

发布于 2014-03-20 09:44:29

HeightWidth of ImageView改为match_parent

代码语言:javascript
运行
复制
<ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/background" />

编辑-

完整的代码-

代码语言:javascript
运行
复制
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.newapp.Firstscreen$PlaceholderFragment" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/background" />

</RelativeLayout>
票数 1
EN

Stack Overflow用户

发布于 2014-03-20 09:47:18

将这一行添加到ImageView中

代码语言:javascript
运行
复制
 android:scaleType="fitXY"

并将宽度和高度设置为match_parent。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22528851

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档