【问题标题】:Android background Image to fill screenAndroid背景图片填满屏幕
【发布时间】:2012-05-21 04:00:24
【问题描述】:

如何让我的相对布局像这样显示我的图像视图:

而不是这个?:

我希望我的布局尽可能多地显示图像并裁剪图像的外部,例如当您在窗口中将桌面背景图像设置为“填充”时:

到目前为止我的 xml 布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" android:fitsSystemWindows="true" android:alwaysDrawnWithCache="false">

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true" android:src="@drawable/background_race_light"/>

    <LinearLayout
        android:id="@+id/linearLayout1"
        style="@style/SessionResumeBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/home_resumeSessionBar_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Medium Text"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <Button
            android:id="@+id/home_resumeSessionBar_buttonResume"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Resume" />
    </LinearLayout>





</RelativeLayout>

【问题讨论】:

    标签: android android-layout


    【解决方案1】:

    为您的图像视图添加比例类型。有几种类型。你需要的是

    android:scaleType="center"
    

    page 将帮助解释所有不同的类型。

    【讨论】:

      【解决方案2】:

      ImageView 布局参数设置为 match_parent 并将比例类型设置为满足您需求的适当比例类型:

      <ImageView
          android:id="@+id/imageView1"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:layout_alignParentLeft="true"
          android:scaleType="centerCrop"
          android:layout_alignParentTop="true" android:src="@drawable/background_race_light"/>
      

      【讨论】:

      • scale_type="center_crop" 现在是 scaleType="centerCrop"
      【解决方案3】:

      ImageView中设置scalexy = true

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2022-12-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-08-18
        相关资源
        最近更新 更多