【问题标题】:How can I stretch background horizontally in xml style?如何以 xml 样式水平拉伸背景?
【发布时间】:2019-01-21 23:07:10
【问题描述】:
我正在尝试将calendar_header.png 中的垂直线水平拉伸为 xml 样式的背景:
<style name="CaldroidCalendarViewLayout">
<item name="android:background">@drawable/calendar_header</item>
</style>
但它会通过背景高度改变控件的高度。我该如何解决?我只想用拉伸的背景填充控件的实际大小。 (它的作用就像背景图像是内容的一部分 - 而不是它只是一个背景。)
【问题讨论】:
标签:
java
android
xml
android-layout
styles
【解决方案1】:
以下答案对我有帮助:https://stackoverflow.com/a/19405297/865475
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView
android:src="@drawable/activation_popup"
android:scaleType="fitXY"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_alignTop="@+id/activation_layout"
android:layout_alignBottom="@id/activation_layout"
android:layout_alignLeft="@id/activation_layout"
android:layout_alignRight="@id/activation_layout"
android:contentDescription="@string/act_code_label" />
<LinearLayout
android:id="@id/activation_layout"
android:clipToPadding="true"
android:padding="25dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<!-- LinearLayout wraps a bunch of smallish views here -->
</LinearLayout>
</RelativeLayout>