每当我将背景分配给使用wrap_content布局的视图时,如果背景图像大于视图,则视图会被拉伸,以便它可以保持整个背景.为什么会如此以及如何预防呢?即使图像是9-patch并且标记了可伸展区域,也会出现这种情况 - 为什么图像缩小到视图的大小?
Mar*_*zon 10
您可以使用RelativeLayout并在其中创建两个元素.用于背景的ImageView和用于内容的另一个视图.使用android:layout_alignBottomto到ImageView并将值设置为内容视图的ID.还要将ImageView的scaleType设置为fitXY.
<RelativeLayout android:id="@+id/relativeLayout1"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_width="fill_parent">
<ImageView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="@drawable/chronometer_bg"
android:id="@+id/imageView_chronometerBackground"
android:layout_alignBottom="@id/chronometer" />
<Chronometer android:text="Chronometer"
android:id="@+id/chronometer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:textSize="32sp"
android:gravity="center" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
21766 次 |
| 最近记录: |