线性布局中的背景图像尺寸不合适

时间:2011-06-06 20:44:18

标签: android android-layout

我用背景图片做了一个线性布局,一个png ...我不知道如何将它显示在布局中(并居中)保持比例......这里是代码

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

显然,图像的高度和宽度与显示器相同......任何帮助?提前致谢

=。4.S =

3 个答案:

答案 0 :(得分:8)

谢谢大家^^我用这种方式解决了:

<?xml version="1.0" encoding="utf-8"?>

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">


    <ImageView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/background"
        android:layout_gravity="center"/>


    <ListView android:id="@+id/android:list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:divider="#FFFFFF"
        android:layout_weight="2"
        android:drawSelectorOnTop="false"
        android:layout_gravity="center"/>

</FrameLayout>

答案 1 :(得分:0)

如果您不想拉伸图片,可以使用重力设置我们而不是png的BitmapDrawable。
请参阅文档:Bitmap

答案 2 :(得分:0)

试试这个相关的问题/答案:

Android: Scale a Drawable or background image?

我没试过,但听起来和你说的相似。