【问题标题】:Android RelativeLayout alignParentRight does not properly align ImageviewAndroid RelativeLayout alignParentRight 没有正确对齐 Imageview
【发布时间】:2011-08-03 07:08:04
【问题描述】:

我正在尝试将 ImageView 放在显示屏的右下角。我希望图像动态扩展以适应不同尺寸的显示。

当图像较小且未设置为展开时,图像会正确对齐,但是当将其设置为 fill_parent 时,图像会向左移动并且不再与显示器的右侧对齐。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <SurfaceView 
        android:id="@+id/surface1" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        ></SurfaceView>
    <ImageView 
        android:src="@+drawable/image_1_patched" 
        android:layout_height="fill_parent" 
        android:id="@+id/imageView1" 
        android:layout_width="fill_parent"
        android:layout_alignParentRight="true"
        ></ImageView>
</RelativeLayout>

如何使图像占据尽可能多的空间并保持与显示器右侧齐平?

【问题讨论】:

    标签: android android-relativelayout alignment


    【解决方案1】:

    将图像视图的 scaletype 设置为 FIT_XY。

    【讨论】:

    • 我厌倦了 fitCenter,但正如您所料,图像留在了中心。然而 fitEnd 将图像对齐到右侧和底部。感谢您为我指明正确的方向。
    • 不用担心。我复制了错误的标签。根据您希望它的扩展方式,有多种选择。 fitXY 如果您不关心图像的纵横比。
    【解决方案2】:

    我知道这可能无法解决问题,但如果您希望图像保持在底部,您可能需要将其添加到您的图像视图 android:layout_alignParentBottom="true"

    【讨论】:

      猜你喜欢
      • 2014-01-08
      • 2013-08-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-07
      • 2018-07-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多