如何包装内容的看法,而不是背景绘制? [英] How to wrap content views rather than background drawable?

查看:80
本文介绍了如何包装内容的看法,而不是背景绘制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何获得的LinearLayout(或任何其他的ViewGroup)承担的大小是孩子的意见,而不是假设的背景图​​像的尺寸?

How can I get a LinearLayout (or any other ViewGroup) to assume the size of it's child views rather than assuming the size of the background image?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="@drawable/large_image300x300pix">

 <TextView android:id="@+id/TextView01" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Hello world!"/>
</LinearLayout>

的线性布局变得尺寸相同的背景图像。 我怎样才能让我的线性布局,承担相同大小的TextView?

The linear layout becomes the same size as the background image. How can I get my linear layout to assume the same size as the textview?

推荐答案

好了,这个线程是有点老了,但我有一个人可能有一天发现有用的解决方案。我认为Android有大量缩放图像下来的问题,所以的LinearLayout大小就结束了碰撞的背景绘制位图,以及ImageView的最终高抬父容器的大小。

OK, so this thread is a little old, but I have a solution that someone might someday find useful. I think Android has problems scaling large images down, so the LinearLayout size ends up getting bumped by the background drawable bitmap, and the ImageView ends up forcing up the size of the parent container.

除非你使用相对布局。可以使相对的LinearLayout的位置ImageView的,即使当ImageView的是在父布局后面。我的解决方案看起来是这样的:

Unless you use a relative layout. You can make the ImageView relative to the position of the LinearLayout, even when the ImageView is behind the layout in the parent. My solution looks something like this:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView
    android:src="@drawable/activation_popup"
    android:scaleType="fitXY"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_alignTop="@+id/activation_layout"
    android:layout_alignBottom="@id/activation_layout"
    android:layout_alignLeft="@id/activation_layout"
    android:layout_alignRight="@id/activation_layout"
    android:contentDescription="@string/act_code_label" />
<LinearLayout
    android:id="@id/activation_layout"
    android:clipToPadding="true"
    android:padding="25dp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical" >
    <!-- LinearLayout wraps a bunch of smallish views here -->
</LinearLayout>
</RelativeLayout>

我想这在显示尺寸和操作系统版本的顶部,似乎工作太棒了。请注意,在LinearLayout中填充是一种技巧,使空间的背景图像图形阴影边框。所述的LinearLayout不需要任何相对定位,因为左上假设

I tried this on a top of display sizes and OS versions, seems to work great. Note that the padding in the LinearLayout is a trick to make space for a shadow border in the background image graphic. The LinearLayout doesn't need any relative positioning because top left is assumed.

这篇关于如何包装内容的看法,而不是背景绘制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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