[英]How can I scale an image up and centre it at the bottom of its container?
I'm trying to make a very simple layout with the following properties: 我正在尝试使用以下属性制作一个非常简单的布局:
Here's an example of what it should look like: 这是它的外观示例:
I can get it to scale up and centre horizontally and vertically by setting the image to match_parent
width and height and specifying scaleType
of fitCentre
. 通过将图像设置为
match_parent
宽度和高度并指定scaleType
的fitCentre
我可以使其在水平和垂直方向上进行缩放和居中。 I could also get it to align to the bottom-right by using fitEnd
. 我还可以通过使用
fitEnd
与右下角对齐。
I tried using RelativeLayout
to centre it at the bottom, but I could only get this to work if I set the image's width and height to wrapContent
, which caused it to not scale up. 我尝试使用
RelativeLayout
将其居中放置在底部,但是如果将图像的宽度和高度设置为wrapContent
,这将导致它无法按比例wrapContent
,那么我只能使其工作。
Here's a sample layout to use as a starting point: 这是一个示例布局,可以用作起点:
<?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>
Try this: 尝试这个:
<?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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.