【问题标题】:How to make background stretch in Android layout如何在Android布局中进行背景拉伸
【发布时间】:2011-12-27 15:14:53
【问题描述】:

所以我要做的是显示列表行元素的背景。我已经创建了行布局并应用了样式:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout1" android:layout_width="fill_parent"
android:layout_height="fill_parent"
style="@style/product1" >

我将样式设置为:

<style name="product1">
     <item name="android:background">@drawable/product1</item>
</style>

product1.xml 为:

<?xml version="1.0" encoding="utf-8"?>
<bitmap
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/prod1"
    android:antialias="true"
    android:dither="true"
    android:filter="false"
    android:gravity="right"
    android:scaleType="fitXY" />

prod1.9.png 是一个九个补丁集,可在顶部和左侧进行缩放(所以我希望我的图像位于右下角)

但我现在面临的问题是图标显示在角落,而 9patch 没有向左和向上缩放。

如果我不使用样式,而是使用android:background=@drawable/prod1,那么它会缩放,但每一行都会变得非常大。有什么想法吗?

【问题讨论】:

    标签: android listview layout background


    【解决方案1】:

    我没有用你的代码验证这一点,但首先想到的是(假设使用 'android:background' 而不是样式),而不是在行布局上:

    android:layout_height="fill_parent"
    

    设置固定高度:

    android:layout_height="30dp"
    

    它没有那么灵活,但它可能适合您的需求。

    【讨论】:

    • 高度很好。是宽度太小了。显然,将宽度设置为固定大小不适用于横向和纵向。
    猜你喜欢
    • 1970-01-01
    • 2013-09-20
    • 1970-01-01
    • 2013-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多