从拉伸的看法prevent背景图片 [英] Prevent background image from stretching the view

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

问题描述

每当分配背景到铺有WRAP_CONTENT的图,如果背景图像比的图时,图像被拉伸,以便它可以容纳整个背景。为什么会这样,以及如何prevent呢?它发生,即使图像9补丁,并具有拉伸区域标记 - 为什么不是图像缩小到视图的大小

Whenever I assign background to a view that is laid out with wrap_content, if the background image is larger than a view, the view is stretched so that it can hold the entire background. Why is it so and how to prevent it? It occurs even if the image is 9-patch and has stretchable areas marked - why isn't the image shrunk to the size of the view?

推荐答案

您可以使用RelativeLayout的,并在里面创建两个元素。一个ImageView的背景和另一种观点认为对您的内容。使用安卓layout_alignBottom 的ImageView的和值设置为你的内容视图的ID。另外设置的ImageView的scaleType到fitXY。

You can use RelativeLayout and create two elements inside it. An ImageView for the Background and another view for your content. Use the android:layout_alignBottom to the the ImageView and set the value to the id of your content view. Also set the scaleType of the ImageView to fitXY.

<RelativeLayout android:id="@+id/relativeLayout1" 
  android:layout_height="wrap_content" 
  android:layout_gravity="center" 
  android:layout_width="fill_parent">

<ImageView android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:scaleType="fitXY"
  android:src="@drawable/chronometer_bg"
  android:id="@+id/imageView_chronometerBackground"
  android:layout_alignBottom="@id/chronometer" />

<Chronometer android:text="Chronometer"
      android:id="@+id/chronometer" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_centerHorizontal="true"
      android:textSize="32sp"
      android:gravity="center" />

</RelativeLayout>

这篇关于从拉伸的看法prevent背景图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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