在LinearLayout中尺度背景图片 [英] Scale background image in LinearLayout

查看:709
本文介绍了在LinearLayout中尺度背景图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下问题;

我在它滚动型,在滚动型是一些自定义视图的LinearLayout。现在,我想提出一个形象的的LinearLayout的背景下,保持图像的原始大小。但是,当我设置的LinearLayout的背景属性它拉伸以适应整个屏幕。我怎样才能让这个图象保持其原来的大小?

我的XML:

 < XML版本=1.0编码=UTF-8&GT?;
<的LinearLayout
  的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
  机器人:ID =@ + ID /根
  机器人:layout_width =FILL_PARENT
  机器人:layout_height =FILL_PARENT
  机器人:背景=@可绘制/ some_drawable>
  <滚动型
    机器人:ID =@ + ID /滚动视图
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_width =FILL_PARENT
    机器人:fillViewport =真正的>
    < some.custom.layout
        机器人:ID =@ + ID / mainLayout
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_width =FILL_PARENT
        />
  < /滚动型>
< / LinearLayout中>
 

解决方案

尝试使用的FrameLayout与ImageView的和的LinearLayout内。例如,尝试改变图像的α和移动在你的FrameLayout到前台,从而LinearLayout中岿然不动的背景。希望这有助于!

I'm having the following problem;

I have a LinearLayout with in it a ScrollView, in the ScrollView is some custom view. Now I want to put an image in the background of the LinearLayout and keep the image in its original size. But when I set the background property of the LinearLayout it stretches to fit the full screen. How can I make it so that the image keeps its original size?

My xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/root"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:background="@drawable/some_drawable">
  <ScrollView
    android:id="@+id/scrollview"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:fillViewport="true">
    <some.custom.layout
        android:id="@+id/mainLayout"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        />
  </ScrollView>
</LinearLayout>

解决方案

Try using FrameLayout with an ImageView and LinearLayout inside. For example, try changing the alpha of the image and move it to foreground in your FrameLayout, thus the LinearLayout stays on background. Hope this helps!

这篇关于在LinearLayout中尺度背景图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆