在 LinearLayout 中缩放背景图像 [英] Scale background image in LinearLayout

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

问题描述

我遇到了以下问题;

我有一个带有 ScrollView 的 LinearLayout,在 ScrollView 中是一些自定义视图.现在我想在 LinearLayout 的背景中放置一个图像并保持图像的原始大小.但是当我设置 LinearLayout 的背景属性时,它会拉伸以适应全屏.如何使图像保持其原始大小?

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?

我的 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>

推荐答案

尝试使用带有 ImageView 和 LinearLayout 的 FrameLayout.例如,尝试更改图像的 alpha 并将其移动到 FrameLayout 中的前景,因此 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天全站免登陆