【发布时间】:2014-07-02 09:43:59
【问题描述】:
在横向模式下,我的背景图片会拉伸,我希望图片放大而不是拉伸以适应尺寸。从我所见,我必须将其添加到它自己的布局中(例如LinearLayout)或“ImageView”,并且在视图上具有内容的布局,我这样说是否正确?
我当前的 xml 布局如下所示:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/instructions"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/photo_background"
android:tag="layout" >
<ScrollView
android:id="@+id/scroll_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fadingEdge="none" >
<include layout="@layout/instructions_internal" />
</ScrollView>
其中包括以下布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scroll_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:id="@+id/instructionsLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/transparent_black" >
<RelativeLayout
android:id="@+id/more_info"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<WebView
android:id="@+id/top_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" />
<Button
android:id="@+id/test"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_below="@+id/top_content"
android:layout_marginBottom="10dp"
android:layout_centerHorizontal="true"
android:onClick="onClickHandler" />
<Button
android:id="@+id/instructionsbutton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/test"
android:background="@color/dark_gray"
android:drawableLeft="@drawable/arrow_down_float"
android:gravity="left|center"
android:onClick="onMoreInstructions"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:text="@string/more_instructions_start"
android:textColor="@color/solid_white" />
</RelativeLayout>
<WebView
android:id="@+id/bottom_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_below="@+id/more_info"
android:layout_marginTop="10dp" />
</RelativeLayout>
我们将不胜感激任何有关这方面的指导。谢谢
【问题讨论】:
-
因此,不要使用容器的 background 属性,而是使用 ImageView (match_parent, match_parent) src 属性。并将 scaleType 设置为 FIT_XY
-
您已将背景图片放在所有可绘制文件夹上,也用于横向定位
-
@DerGolem 实际上,我相信
FIT_XY会做同样的事情。 OP 正在寻找CENTER_CROP或CENTER_INSIDE。 -
@IvanBartsov:你说得对,赶时间(午餐时间),但概念仍然存在:使用 ImageView 的 src 而不是容器的背景。
标签: android android-layout background scaling