如何放大图像并将其居中放置在容器底部?

山姆

我正在尝试使用以下属性制作一个非常简单的布局:

  • 仅包含应为以下内容的单个图像:
    • 在保持其原始宽高比的同时尽可能地放大
    • 水平居中
    • 在其容器的底部

这是它的外观示例:

纵向视图,显示图像居中于底部但按比例放大横向视图,显示图像居中于底部但按比例放大

我可以得到它由图像设置为水平和垂直比例放大和中心match_parent的宽度和高度与指定scaleTypefitCentre我也可以使用使其与右下角对齐fitEnd

我曾尝试将RelativeLayout其居中放置在底部,但是如果将图像的宽度和高度设置为wrapContent,这将导致它无法按比例放大,那么我只能使它起作用

这是一个示例布局,可以用作起点:

<?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" >

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_gravity="bottom|center_horizontal"
        android:scaleType="fitStart"
        android:src="@drawable/abc_ic_search" />

</RelativeLayout>
paulina_glab

试试这个:

<?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">

    <ImageView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:scaleType="fitCenter"
            android:src="@drawable/abc_ic_search"
            android:adjustViewBounds="true"
            android:layout_alignParentBottom="true"/>

</RelativeLayout>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章